问题
In this guide, a MobileUser is set after calling MobileServiceClient.LoginAsync. I'm thinking that the MobileUser returned by MobileServiceClient.LoginAsync is the same as the MobileServiceClient.CurrentUser after logging in via LoginAsync.
I printed out both the tokens they contain by calling the MobileServiceAuthenticationToken property (i.e. MobileUser.MobileServiceAuthenticationToken and MobileService.CurrentUser.MobileServiceAuthenticationToken).
The two tokens seem to be the same. The two tokens have the same payload as decoded in jwt.io I also pasted both tokens in Sublime Text 2 and the said editor recognizes the two tokens as the same since using ctrl+D also selects the other token.
Is it safe to assume that the two tokens are the same and the two MobileServiceUsers are the same?
This might look like a weird question but i'm trying to debug a problem in the client code and need to check that it's not because of changing the code from the guide.
回答1:
Yes, the tokens are the same. After a successful login, the CurrentUser is populated with the results of your LoginAsync call. This allows all subsequent calls to your service to include the token and lets you access the CurrentUser details without needing to store that info yourself.
Here's the code in the C# client that does this: https://github.com/Azure/azure-mobile-apps-net-client/blob/master/sdk/src/Microsoft.WindowsAzure.MobileServices/Authentication/MobileServiceAuthentication.cs#L148
来源:https://stackoverflow.com/questions/35592818/is-the-token-in-mobileserviceclient-currentuser-after-loginasync-and-token-of-mo