예제 #1
0
        private async Task <BudgeterToken> GetTokenFromAuthCode()
        {
            if (string.IsNullOrEmpty(TokenRequest.ClientId) || string.IsNullOrEmpty(TokenRequest.Code) || string.IsNullOrEmpty(TokenRequest.CodeVerifier) || string.IsNullOrEmpty(TokenRequest.RedirectUri))
            {
                throw new CallerException("Missing fields for a authorization_code grant.");
            }

            await new AppValidator(Cache, AuthContext).ValidateAuthCodeTokenRequest(TokenRequest, AuthHeader);

            int userId = await new AuthCodeLogic(Cache).ValidateCode(TokenRequest);

            var securityRoles = await new UserSecurityRoleLogic(AuthContext).GetSecurityRoles(userId);

            var tokenIssuer = new TokenIssuer(EnvironmentRequester, AuthContext, UserContext, Cache);

            var accessTokenData = await tokenIssuer.IssueToken(userId, TokenRequest.ClientId, securityRoles, TokenType.AuthCode);

            var refreshTokenData = await tokenIssuer.IssueToken(userId, TokenRequest.ClientId, null, TokenType.Refresh);

            return(new BudgeterToken
            {
                AccessToken = accessTokenData.Key,
                RefreshToken = refreshTokenData.Key,
                ExpiresIn = accessTokenData.Value
            });
        }
        // Right now no security roles will exist for a federated token.
        public async Task <BudgeterToken> IssueFederatedIdentityToken(int userId, string audience, string provider)
        {
            var tokenIssuer = new TokenIssuer(EnvironmentRequester, AuthContext, UserContext, Cache);

            var accessTokenData = await tokenIssuer.IssueToken(userId, audience, null, TokenType.Federated, provider);

            return(new BudgeterToken
            {
                AccessToken = accessTokenData.Key,
                ExpiresIn = accessTokenData.Value
            });
        }