示例#1
0
        public override async Task <AuthenticationState> GetAuthenticationStateAsync()
        {
            var data = await _localStorage.GetAsync();

            if (string.IsNullOrWhiteSpace(data.Token))
            {
                return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity())));
            }

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

            return(new AuthenticationState(ClaimsPrincipalGenerator.BuildClaimsPrincipal(data.Token, data.UserName)));
        }
        async public Task AddTokenAsync(HttpClient httpClient)
        {
            var tokenInfo = await _globeDataStorage.GetAsync();

            if (tokenInfo != null && !string.IsNullOrWhiteSpace(tokenInfo.Token))
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", tokenInfo.Token);
            }
            else
            {
                httpClient.DefaultRequestHeaders.Authorization = null;
            }
        }