Exemplo n.º 1
0
        private async Task MarkUserAsAuthenticated(SavedToken savedToken)
        {
            var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, savedToken.SavedLR.UserId) }, "apiauth"));
            var authState         = Task.FromResult(new AuthenticationState(authenticatedUser));
            await _localStorage.SetItemAsync("authToken", savedToken.SavedLR.Token);

            await _localStorage.SetItemAsync("tokenExpire", savedToken.SavedLR.ExpirationDate);

            _genericRepository.SetToken(savedToken.SavedLR.Token);
            NotifyAuthenticationStateChanged(authState);
        }
Exemplo n.º 2
0
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            SavedToken savedToken = await GetTokenAsync();

            if (string.IsNullOrWhiteSpace(savedToken.SavedLR.Token))
            {
                firstTimeThrough = false;
                return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
            }
            if (firstTimeThrough)
            {
                firstTimeThrough = false;
                await MarkUserAsAuthenticated(savedToken);
            }
            return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(savedToken.Claims, "jwt"))));
        }
Exemplo n.º 3
0
        //Public interface...no need for claims to be exposed
        public async Task MarkUserAsAuthenticated(LoginResult lr)
        {
            SavedToken st = await ParseToken(lr);

            await MarkUserAsAuthenticated(st);
        }