Exemple #1
0
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            if (_accessor.IsServerStarted())
            {
                _token = await _storage.GetAsync <string>(TokenKey);
            }

            Console.WriteLine($"Token is {_token}");

            if (!string.IsNullOrWhiteSpace(_token))
            {
                var jwtToken = new JwtSecurityToken(_token);

                if (jwtToken.ValidTo > DateTime.UtcNow)
                {
                    _httpClientService.SetAuthorization(_token);

                    var identity = new ClaimsIdentity(jwtToken.Claims, AuthenticationType);

                    return(new AuthenticationState(new ClaimsPrincipal(identity)));
                }
            }

            _token = null;

            if (_accessor.IsServerStarted())
            {
                await _storage.DeleteAsync(TokenKey);
            }

            _httpClientService.RemoveAuthorization();

            return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
        }
Exemple #2
0
        private async Task <T> GetStoredItemOrResetAsync <T>(string key, T defaultValue = default)
        {
            try {
                return(await _localStorageService.GetAsync <T>(key));
            } catch {
                await _localStorageService.DeleteAsync(key);

                return(defaultValue);
            }
        }
Exemple #3
0
 public async Task RemoveSavedPlayerIdAsync()
 {
     await _preferenceStore.DeleteAsync(PreferredPlayerIdKey);
 }