Consume Authorize using C#


#1

Hello there!

I am pulling my hair here. Trying to authorize against the API using C# but I have no idea how to parse the response I get having used the API-instructions. I call

https://api.lockitron.com/oauth/authorize and to this I add the client_id, response_type and redirect_uri. Response is a complete webpage and all I want to try is to get the code in return.

Other than this I have tried using the restClient-add on in Firefox which returns the accesstoken (but is getting the authorize-code in the background).

I feel like a complete noob and would like for examples on how to consume the authorize using C#.


#2

@Joakim_Mansson unfortunately I know about ziltch on C#. When you note:

Response is a complete webpage and all I want to try is to get the code in return.

You’re on the last OAuth step? Have you done the OAuth handshake in any other C# app?


#3

No. Sorry for being so unclear. I am at:
“Getting the Authentication Code”.

This is a screenshot of the c#-code I have got and in the succes-scope I would like to read the authentication code.


#4

@Joakim_Mansson I walked through this on my end; as expected, this successfully yields an authorization code. In turn, you need to POST this code along with the parameters listed at https://api.lockitron.com/#auth_code.

Take a look at https://www.digitalocean.com/community/tutorials/an-introduction-to-oauth-2 for a helpful overview on OAuth 2 flows; you’ll need the redirect_uri to be an actual app where you can capture the code. I suspect there is a C# library that handles this handshake for you to grab the token, but I don’t know too much about the language.


#5

I am a bit lost here. I do get a response from the server in response.Content but I don’t know which result to read in the response as “authentication code”. Is it in the header or in the body?


#6

I believe it’s returned as a parameter in the query string (during the redirect).