Search code examples
nest-api

Could you explain how to generate pincode in android code


I'm struggling to generate pincode in source code. Actually I can't even guess how to do that. I'v already read nest doc about how to make pincode. I understood that just copy url with client id and secret. And paste it to the address bar. If a user accept that, we can achieve the pincode. Is it true that user find the pincode at the first prior to develper?
If I have lots of user, how can they(users) confirm pincode one by one? even though user exists only one. I think, they aren't interested in that code. Pincode is necessary for only develper.

Could you explain how to make pincode in source code? Thank you for reading this.


Solution

  • PIN codes are indeed one per user, you are asking your user for access to their Nest account.

    Flow is generally:

    1. User logs into your app/account
    2. User click your pair with Nest button and you load the Auth URL in a WebView
    3. User logs into their Nest account and grants permissions
    4. Either a PIN code, or a redirect with access code is returned (configurable by you)
    5. Your app sends access code, secret, and client ID to Nest to get an access token, which you store like a password and use to access the Nest API on behalf of the user.

    The Android Sample code from Nest includes the authorization flow, and is likely what you want: https://github.com/nestlabs/android-NestDK/blob/master/NestLib/src/main/java/com/nestapi/lib/UserAuthActivity.java