예제 #1
0
        async Task LoadCachedTokenAsync()
        {
            StoreSettings settings = await ReadSettingsAsync();

            if (settings != null)
            {
                try
                {
                    if (!string.IsNullOrEmpty(settings.AuthToken) &&
                        JwtUtility.GetTokenExpiration(settings.AuthToken) > DateTime.UtcNow &&
                        JwtUtility.IsIntendedForAudience(settings.AuthToken, ApiKeys.ApiUrl))
                    {
                        MobileService.CurrentUser = new MobileServiceUser(settings.UserId);
                        MobileService.CurrentUser.MobileServiceAuthenticationToken = settings.AuthToken;
                    }
                    else
                    {
                        await ClearOldCredentials(settings);
                    }
                }
                catch (InvalidTokenException)
                {
                    await ClearOldCredentials(settings);
                }
            }
        }
예제 #2
0
        async Task LoadCachedTokenAsync()
        {
            StoreSettings settings = await ReadSettingsAsync();

            if (settings != null)
            {
                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;

                    await SaveSettingsAsync(settings);
                }
            }
        }