Пример #1
0
        public async Task <Result <AuthenticationTokens> > ExchangeAuthenticationTokensAsync(AuthenticationTokens tokens)
        {
            #region AccessToken Validation

            Result <ClaimsPrincipal> accessTokenValidationResult =
                await accessTokenService.ValidateTokenAsync(tokens.AccessToken);

            if (!accessTokenValidationResult.Succeeded)
            {
                return(Result <AuthenticationTokens> .Failure(accessTokenValidationResult.Errors));
            }

            ClaimsPrincipal tokenClaims = accessTokenValidationResult.Response;

            #endregion

            #region RefreshToken Validation

            Result refTokenValResult =
                await refreshTokenService.ValidateTokenAsync(tokens.RefresthToken);

            if (!refTokenValResult.Succeeded)
            {
                return(Result <AuthenticationTokens> .Failure(refTokenValResult.Errors));
            }

            #endregion

            #region Token Generation

            string   clientId = accessTokenService.GetCustomerIdFromClaims(tokenClaims);
            Customer client   = await clientManager.FindByIdAsync(clientId);

            return(await GenerateAuthenticationTokensAsync(client));

            #endregion
        }