Closed niels9001 closed 7 years ago
Yes, you can store the accessToken
in your app and use it to connect to the bridge later. I think the token is not needed anymore.
I'm not sure about the RegisterBridgeAsync
, maybe if you use the same app id it is not needed. Test it and let me know the results.
Thanks, I'll look into the Register stuff to see if necessary.
So, as I understand now you follow the code here when setting it up for the first time. (https://github.com/Q42/Q42.HueApi/blob/master/RemoteApi.md) for the first connection / registration.
But the 2nd time the app launches, how do we then use the RemoteClient? How do we use the authClient.GetValidToken then?
Good point. The access token and refresh token are only valid for a limited amount of time. So I guess you'll have to go through the whole authentication process again. There must be an easier way, maybe you can ask Philips how you should handle a user that gave permission and connects for a second time. Or play around with the sample to see what works best.
I'm not sure, I just created a simple sample app that works but have no further info.
I checked with Philips, and I got some good feedback that validates your point. On the access/refresh tokens:
"The authentication code that you get at the begin is only valid for a few minutes. With this, you can get the access tokens. The access tokens are valid for 7 days and the refreshtokens for 100 days. With the refreshtokens you can get a new set of accesstokens and refreshtokens. So what you need to do is to see if the accesstokens are still valid. You could do this with a call, find out that the accesstoken has been expired and then take action. If the refreshtoken has been expired the user would need to log in."
On registration:
Registration is only necessary if the app hasn't registered locally yet. If this has already been done you don't need to do it again, only if you'd want to keep them explicitely seperate.
Ok thanks. I'll create an extra method so you an initialize the RemoteAuthenticationClient with a access and refresh token.
You can now initialize the remote authentication client with existing tokens. Example in comments here: https://github.com/Q42/Q42.HueApi/blob/master/src/Q42.HueApi.RemoteApi.Sample/MainPage.xaml.cs#L48-L51
Should be enough to create an app that uses the remote api.
Sorry for this :(, to me it's not entirely clear when to use what: https://github.com/Q42/Q42.HueApi/blob/master/RemoteApi.md
Is my thinking correct?
IRemoteAuthenticationClient authClient = new RemoteAuthenticationClient(clientId, clientSecret, appId); authClient.BuildAuthorizeUri("sample", "consoleapp"); var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, authorizeUri, callbackUri); var accessToken = await authClient.GetToken(result.Code);