public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token)) { return(Anonimo); } var tiempoExpiracionString = await js.GetFromLocalStorage(EXPIRATIONTOKENKEY); DateTime tiempoExpiracion; if (DateTime.TryParse(tiempoExpiracionString, out tiempoExpiracion)) { if (TokenExpirado(tiempoExpiracion)) { await Limpiar(); return(Anonimo); } if (DebeRenovarToken(tiempoExpiracion)) { token = await RenovarToken(token); } } return(ConstruirAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token)) { return(Anonimo); } string expirationTokenKey = await js.GetFromLocalStorage(EXPIRATIONTOKENKEY); DateTime expirationTime; if (DateTime.TryParse(expirationTokenKey, out expirationTime)) { if (TokenHasExpired(expirationTime)) { await ClearStorage(); return(Anonimo); } else { if (HasToRenovateToken(expirationTime)) { token = await RenovateToken(token); } } } return(ConstruirAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token)) { return(Anonymous); } var expirationTimeString = await js.GetFromLocalStorage(EXPIRATIONTOKENKEY); DateTime expirationTime; if (DateTime.TryParse(expirationTimeString, out expirationTime)) { if (IsTokenExpired(expirationTime)) { await CleanUp(); return(Anonymous); } if (ShouldRenewToken(expirationTime)) { token = await RenewToken(token); } } return(BuildAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token)) { return(Anonymous); } return(BuildAuthenticationState(token)); }
public override async Task<AuthenticationState> GetAuthenticationStateAsync() { var token = await _js.GetFromLocalStorage(_TOKEN_KEY_); if (string.IsNullOrEmpty(token)) { return _anonynous; } return BuildAuthenticationState(token); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(tokenKey); if (string.IsNullOrEmpty(token)) { return(notAuthenticate); } return(CreateAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token) || token == "null") { return(Anonimo); } return(ConstruirAuthenticationState(token)); }
public override async Task <AuthenticationState> GetAuthenticationStateAsync() { string token = await jsRuntime.GetFromLocalStorage(tokenKey); string expiration = await jsRuntime.GetFromLocalStorage(tokenLive); if (string.IsNullOrEmpty(token) && string.IsNullOrEmpty(expiration)) { return(Anonymous); } if (DateTime.Now > DateTime.Parse(expiration)) { await Logout(); return(Anonymous); } return(BuildAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { //guardaremos el JWT en el LocalStorage //vificando si existe token en local storgae var token = await js.GetFromLocalStorage(TOKENKEY); if (string.IsNullOrEmpty(token)) { return(Anonimo); } return(contruirAthenticationState(token)); }
public override async Task <AuthenticationState> GetAuthenticationStateAsync() { // Read token from Local Storage var token = await _js.GetFromLocalStorage(JWT_TOKEN_KEY); if (string.IsNullOrEmpty(token)) { return(Anonymous); } return(BuildAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); var expire = await js.GetFromLocalStorage(EXPIRATION); if (string.IsNullOrEmpty(token)) { return(Anonymous); } if (DateTime.Parse(expire.ToString()) < DateTime.Now) { await js.RemoveItem(TOKENKEY); await js.RemoveItem(EXPIRATION); NotifyAuthenticationStateChanged(Task.FromResult(Anonymous)); } return(BuildAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await js.GetFromLocalStorage(TOKENKEY); if ( string.IsNullOrEmpty(token) || token.ToLower().Contains("invalid login") || token == "Username or password invalid" ) { return(Anonymous); } return(BuildAuthenticationState(token)); }
public override async Task <AuthenticationState> GetAuthenticationStateAsync() { var token = await JSRuntime.GetFromLocalStorage(TokenKey); return(string.IsNullOrEmpty(token) ? Anonymous : BuildAuthenticationState(token)); }
public async override Task <AuthenticationState> GetAuthenticationStateAsync() { Console.WriteLine("Anonymous"); var token = await _jSRuntime.GetFromLocalStorage(jwtKey); var tokenRefresh = await _jSRuntime.GetFromLocalStorage(tokenRefreshKey); if (string.IsNullOrWhiteSpace(token)) { return(Anonymous); } if (string.IsNullOrWhiteSpace(tokenRefresh)) { return(Anonymous); } JwtSecurityToken decodeToken; try { decodeToken = ReadJwtToken(token); } catch (Exception ex) { Console.WriteLine("Error from server: " + ex.Message); await _jSRuntime.RemoveFromLocalStorage(jwtKey); await _jSRuntime.RemoveFromLocalStorage(tokenRefreshKey); return(Anonymous); } if (decodeToken.ValidTo.ToLocalTime() < DateTime.Now) { try { var tokens = await _accountService.RefreshTokenAsync(new TokenApiModel { Token = token, RefreshToken = tokenRefresh }); await _jSRuntime.SetInLocalStorage(jwtKey, tokens.Token); await _jSRuntime.SetInLocalStorage(tokenRefreshKey, tokens.RefreshToken); token = tokens.Token; tokenRefresh = tokens.RefreshToken; Console.WriteLine("Refreshing ... "); } catch (Exception ex) { Console.WriteLine("Error from server: " + ex.Message); await _jSRuntime.RemoveFromLocalStorage(jwtKey); await _jSRuntime.RemoveFromLocalStorage(tokenRefreshKey); return(Anonymous); } } return(BuildAuthenticationState(token)); }