예제 #1
0
        protected virtual Task AddParametersToRequestAsync(IdentityClientConfiguration configuration, ProtocolRequest request)
        {
            foreach (var pair in configuration.Where(p => p.Key.StartsWith("[o]", StringComparison.OrdinalIgnoreCase)))
            {
                request.Parameters[pair.Key] = pair.Value;
            }

            return(Task.CompletedTask);
        }
예제 #2
0
 protected virtual async Task <DiscoveryDocumentResponse> GetDiscoveryResponse(
     IdentityClientConfiguration configuration)
 {
     using (var httpClient = HttpClientFactory.CreateClient()) {
         return(await httpClient.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest {
             Address = configuration.Authority,
             Policy =
             {
                 RequireHttps = configuration.RequireHttps
             }
         }));
     }
 }
예제 #3
0
        protected virtual Task <ClientCredentialsTokenRequest> CreateClientCredentialsTokenRequestAsync(
            DiscoveryDocumentResponse discoveryResponse,
            IdentityClientConfiguration configuration)
        {
            var request = new ClientCredentialsTokenRequest {
                Address      = discoveryResponse.TokenEndpoint,
                Scope        = configuration.Scope,
                ClientId     = configuration.ClientId,
                ClientSecret = configuration.ClientSecret
            };

            AddParametersToRequestAsync(configuration, request);

            return(Task.FromResult(request));
        }
예제 #4
0
        protected virtual async Task <TokenResponse> GetTokenResponse(
            DiscoveryDocumentResponse discoveryResponse,
            IdentityClientConfiguration configuration)
        {
            using (var httpClient = HttpClientFactory.CreateClient()) {
                switch (configuration.GrantType)
                {
                case OidcConstants.GrantTypes.ClientCredentials:
                    return(await httpClient.RequestClientCredentialsTokenAsync(
                               await CreateClientCredentialsTokenRequestAsync(discoveryResponse, configuration),
                               CancellationTokenProvider.Token
                               ));

                case OidcConstants.GrantTypes.Password:
                    return(await httpClient.RequestPasswordTokenAsync(
                               await CreatePasswordTokenRequestAsync(discoveryResponse, configuration),
                               CancellationTokenProvider.Token
                               ));

                default:
                    throw new RocketException("Grant type was not implemented: " + configuration.GrantType);
                }
            }
        }