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

            if (settings != null)
            {
                try
                {
                    if (!string.IsNullOrEmpty(settings.AuthToken) && JwtUtility.GetTokenExpiration(settings.AuthToken) < DateTime.UtcNow)
                    {
                        if (CrossConnectivity.Current.IsConnected)
                        {
                            var result = await RegenerateTokenAsync();

                            if (!result)
                            {
                                //no token regenerated
                                await LogoutAsync();
                            }
                        }
                    }
                }
                catch (InvalidTokenException)
                {
                    //Token exception error
                    if (CrossConnectivity.Current.IsConnected)
                    {
                        await LogoutAsync();
                    }
                }
            }
        }
예제 #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);
                }
            }
        }