public async Task <TokenMintingResponse> MintResourceOwnerTokenAsync(ResourceOwnerTokenRequest resourceOwnerTokenRequest)
        {
            var extensionGrantRequest = ToArbitraryResourceOwnerRequest(resourceOwnerTokenRequest);
            var result = await _tokenEndpointHandlerExtra.ProcessRawAsync(extensionGrantRequest);

            return(ToTokenMintingResponse(result));
        }
Esempio n. 2
0
        public void AddGraphTypeFields(QueryCore queryCore)
        {
            queryCore.FieldAsync <ArbitraryNoSubjectResultType>(name: GrantType,
                                                                description: $"mints a custom {GrantType} token.",
                                                                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ArbitraryNoSubjectInput> > {
                Name = "input"
            }),
                                                                resolve: async context =>
            {
                try
                {
                    var userContext = context.UserContext.As <GraphQLUserContext>();
                    var input       = context.GetArgument <ArbitraryNoSubjectInputHandle>("input");

                    var formValues = new Dictionary <string, StringValues>()
                    {
                        { "grant_type", GrantType },
                        { "client_id", input.client_id },
                        { "client_secret", input.client_secret },
                        { "scope", input.scope },
                        { "arbitrary_claims", input.arbitrary_claims }
                    };
                    if (!string.IsNullOrWhiteSpace(input.arbitrary_amrs))
                    {
                        formValues.Add("arbitrary_amrs", input.arbitrary_amrs);
                    }
                    if (!string.IsNullOrWhiteSpace(input.arbitrary_audiences))
                    {
                        formValues.Add("arbitrary_audiences", input.arbitrary_audiences);
                    }
                    if (input.access_token_lifetime > 0)
                    {
                        formValues.Add("access_token_lifetime", input.access_token_lifetime.ToString());
                    }

                    IFormCollection formCollection = new FormCollection(formValues);

                    var processsedResult = await _tokenEndpointHandlerExtra.ProcessRawAsync(formCollection);

                    if (processsedResult.TokenErrorResult != null)
                    {
                        context.Errors.Add(new ExecutionError($"{processsedResult.TokenErrorResult.Response.Error}:{processsedResult.TokenErrorResult.Response.ErrorDescription}"));
                        return(null);
                    }
                    var result = new ArbitraryNoSubjectResult
                    {
                        access_token = processsedResult.TokenResult.Response.AccessToken,
                        expires_in   = processsedResult.TokenResult.Response.AccessTokenLifetime,
                        token_type   = "bearer"
                    };
                    return(result);
                }
                catch (Exception e)
                {
                    context.Errors.Add(new ExecutionError("Unable to process request", e));
                }
                return(null);
            },
                                                                deprecationReason: null);
        }
        public async Task <TokenRawResult> PostRevocationAsync()
        {
            /*
             * TokenTypHint: [refresh_token,subject,access_token]
             */
            var arbResourceOwnerResult = await PostRefreshAsync();

            var revocationRequest = new RevocationRequest()
            {
                Token             = arbResourceOwnerResult.TokenResult.Response.RefreshToken,
                ClientId          = "arbitrary-resource-owner-client",
                TokenTypHint      = "refresh_token",
                RevokeAllSubjects = "true"
            };
            var revocationResult = await _tokenEndpointHandlerExtra.ProcessRawAsync(revocationRequest);

            var refreshTokenRequest = new RefreshTokenRequest()
            {
                RefreshToken = arbResourceOwnerResult.TokenResult.Response.RefreshToken,
                ClientId     = "arbitrary-resource-owner-client"
            };

            arbResourceOwnerResult = await _tokenEndpointHandlerExtra.ProcessRawAsync(refreshTokenRequest);

            return(arbResourceOwnerResult);
        }