Exemplo n.º 1
0
        public void NotifyUserAuthentication(string token)
        {
            var authenticatedUser = new ClaimsPrincipal(
                new ClaimsIdentity(JwtParser.ParseClaimsFromJWT(token),
                                   "jwtAuthType"));

            var authstate = Task.FromResult(new AuthenticationState(authenticatedUser));

            NotifyAuthenticationStateChanged(authstate);
        }
Exemplo n.º 2
0
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            var token = await _localStorage.GetItemAsync <string>(_config["authTokenStorageKey"]);

            if (string.IsNullOrWhiteSpace(token))
            {
                return(_anonymous);
            }

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

            return(new AuthenticationState(
                       new ClaimsPrincipal(
                           new ClaimsIdentity(JwtParser.ParseClaimsFromJWT(token),
                                              "jwtAuthType"))));
        }