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); }
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 } })); } }
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)); }
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); } } }