コード例 #1
0
        private async Task <SavedToken> ParseToken(LoginResult lr)
        {
            if (string.IsNullOrWhiteSpace(lr.Token))
            {
                return(new SavedToken());
            }
            var tokenExpired = IsTokenExpired(lr.ExpirationDate);

            if (tokenExpired)
            {
                await MarkUserAsLoggedOut();

                return(new SavedToken());
            }
            var    claims = JwtParserHelper.ParseClaimsFromJwt(lr.Token);
            string userId = claims.Where(x => x.Type == "nameid").Select(x => x.Value).FirstOrDefault();

            return(new SavedToken()
            {
                Claims = claims,
                SavedLR = new LoginResult()
                {
                    UserId = userId,
                    Token = lr.Token,
                    ExpirationDate = lr.ExpirationDate
                }
            });
        }
コード例 #2
0
        private async void ShowEmailNotification(string accessToken)
        {
            var claims = JwtParserHelper.ParseClaimsFromJwt(accessToken);
            var otac   = claims.FirstOrDefault(x => x.Type == "otac");

            if (otac != null)
            {
                string ModalParams;
                var    m = new ModalSuccess
                {
                    Title   = _translate.Keys["ConfirmEmail"],
                    Message = _translate.Keys["EmailConfirmation"]
                };
                ModalParams = JsonSerializer.Serialize(m);

                await JsRuntime.InvokeVoidAsync("showModalDialog", ModalParams);
            }
        }
コード例 #3
0
        private async Task MarkUserAsAuthenticated(SavedToken savedToken)
        {
            var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, savedToken.SavedLR.UserId) }, "apiauth"));

            authenticatedUser.AddIdentity(new ClaimsIdentity(JwtParserHelper.ParseClaimsFromJwt(savedToken.SavedLR.AccessToken), "apiauth"));

            var authState = Task.FromResult(new AuthenticationState(authenticatedUser));
            await _localStorage.SetItemAsync("authToken", savedToken.SavedLR.AccessToken);

            await _localStorage.SetItemAsync("refreshToken", savedToken.SavedLR.RefreshToken);

            await _localStorage.SetItemAsync("expireIn", savedToken.SavedLR.ExpiresIn);

            //await _jsRuntime.InvokeAsync<object>("RemoveUnusedParams");
            await _jsRuntime.InvokeMethod("RemoveUnusedParams");

            _genericRepository.SetResponse(savedToken.SavedLR);
            NotifyAuthenticationStateChanged(authState);
        }
コード例 #4
0
        private SavedToken ParseToken(LoginResponse lr)
        {
            if (string.IsNullOrWhiteSpace(lr.AccessToken))
            {
                return(new SavedToken());
            }

            var    claims = JwtParserHelper.ParseClaimsFromJwt(lr.AccessToken);
            string userId = claims.Where(x => x.Type == "sub").Select(x => x.Value).FirstOrDefault();

            return(new SavedToken()
            {
                Claims = claims,
                SavedLR = new LoginResponse()
                {
                    UserId = userId,
                    AccessToken = lr.AccessToken,
                    ExpiresIn = lr.ExpiresIn,
                    RefreshToken = lr.RefreshToken
                }
            });
        }