Is the token in MobileServiceClient.CurrentUser after LoginAsync and token of MobileServiceUser returned by LoginAsync are the same?

守給你的承諾、 提交于 2019-12-12 03:55:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!