Ejemplo n.º 1
0
        public async Task VerifyTokenAsync()
        {
            if ((!string.IsNullOrEmpty(Settings.AuthToken)) && (!string.IsNullOrEmpty(Settings.UserId)))
            {
                try
                {
                    var date = JwtUtility.GetTokenExpiration(Settings.AuthToken).Value.AddMinutes(-30);

                    if (!string.IsNullOrEmpty(Settings.AuthToken) && date < DateTime.UtcNow)
                    {
                        var result = await RegenerateTokenAsync();

                        if (!result)
                        {
                            //no token regenerated
                            await LogoutAsync();
                        }
                    }
                }
                catch (InvalidTokenException)
                {
                    //Token exception error
                    await LogoutAsync();
                }
            }
        }
Ejemplo n.º 2
0
 void LoadCachedTokenAsync()
 {
     try
     {
         if (!string.IsNullOrEmpty(Settings.AuthToken) && JwtUtility.GetTokenExpiration(Settings.AuthToken) > DateTime.UtcNow)
         {
             MobileService.CurrentUser = new MobileServiceUser(Settings.UserId);
             MobileService.CurrentUser.MobileServiceAuthenticationToken = Settings.AuthToken;
         }
     }
     catch (InvalidTokenException)
     {
         Settings.AuthToken = string.Empty;
         Settings.UserId    = string.Empty;
         Settings.Role      = string.Empty;
     }
 }