Search code examples
javaandroidnest-api

How to get the authorization from Nest via firebase API?


I am new to programming for Nest and I am confused about how to get the authorization from Nest via firebase API.

I want to write an App in Android to access device information. I had already registered an account at Nest and created a client from the web interface. I got the Authorization URL at the client page and I used the chrome extension to create 2 virtual devices.

From https://developer.nest.com/documentation/authorization-overview, I know I need to use PIN based method so I am using the following code:

Firebase ref = new Firebase("https://home.nest.com/login/oauth2?client_id=CLIENT_ID&state=STATE");
Log.i(TAG, "getParams " + ref.getParams());

When I log this information, I got the following log:

getParams {}

Can anyone help me obtain authorization from Nest via firebase API?


UPDATE

I have studied the website RIT gave but there are some things I am still confused about.

My client page has the following information:

Client ID:  b4bf4721-2***-4***-a***-c1a*********
Client secret: S578in************
Authorization URL: https://home.nest.com/login/oauth2?client_id=b4bf4721-2***-4***-a***-c1a*********&state=STATE
Access Token URL: https://api.home.nest.com/oauth2/access_token?code=AUTHORIZATION_CODE&client_id=b4bf4721-2***-4***-a***-c1a*********&client_secret=S578in************&grant_type=authorization_code

When I use the following code:

Firebase ref = new Firebase(Authorization URL);

I expect it will return the PIN code, but it doesn't.

Also, from https://developer.nest.com/documentation/how-to-auth, topic 3. Exchange your authorization code for an access token has a command:

"POST https://api.home.nest.com/oauth2/access_token?code=STRING&client_id=STRING&client_secret=STRING&grant_type=authorization_code"

Does anyone knows if there is any firebase API can achieve this command?


Solution

  • Authorization is done following the OAuth 2.0 protocol, once you have a token from that, you can use the Firebase API. The firebase protocol does not provide direct authorization.