|
|
|
@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging.Abstractions; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using System.Threading.Tasks; |
|
|
|
@ -117,26 +118,12 @@ namespace Volo.Abp.IdentityModel |
|
|
|
{ |
|
|
|
case OidcConstants.GrantTypes.ClientCredentials: |
|
|
|
return await httpClient.RequestClientCredentialsTokenAsync( |
|
|
|
new ClientCredentialsTokenRequest |
|
|
|
{ |
|
|
|
Address = discoveryResponse.TokenEndpoint, |
|
|
|
Scope = configuration.Scope, |
|
|
|
ClientId = configuration.ClientId, |
|
|
|
ClientSecret = configuration.ClientSecret |
|
|
|
}, |
|
|
|
await CreateClientCredentialsTokenRequestAsync(discoveryResponse, configuration), |
|
|
|
CancellationTokenProvider.Token |
|
|
|
); |
|
|
|
case OidcConstants.GrantTypes.Password: |
|
|
|
return await httpClient.RequestPasswordTokenAsync( |
|
|
|
new PasswordTokenRequest |
|
|
|
{ |
|
|
|
Address = discoveryResponse.TokenEndpoint, |
|
|
|
Scope = configuration.Scope, |
|
|
|
ClientId = configuration.ClientId, |
|
|
|
ClientSecret = configuration.ClientSecret, |
|
|
|
UserName = configuration.UserName, |
|
|
|
Password = configuration.UserPassword |
|
|
|
}, |
|
|
|
await CreatePasswordTokenRequestAsync(discoveryResponse, configuration), |
|
|
|
CancellationTokenProvider.Token |
|
|
|
); |
|
|
|
default: |
|
|
|
@ -144,5 +131,49 @@ namespace Volo.Abp.IdentityModel |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Task<PasswordTokenRequest> CreatePasswordTokenRequestAsync(DiscoveryResponse discoveryResponse, IdentityClientConfiguration configuration) |
|
|
|
{ |
|
|
|
var request = new PasswordTokenRequest |
|
|
|
{ |
|
|
|
Address = discoveryResponse.TokenEndpoint, |
|
|
|
Scope = configuration.Scope, |
|
|
|
ClientId = configuration.ClientId, |
|
|
|
ClientSecret = configuration.ClientSecret, |
|
|
|
UserName = configuration.UserName, |
|
|
|
Password = configuration.UserPassword |
|
|
|
}; |
|
|
|
|
|
|
|
AddParametersToRequestAsync(configuration, request); |
|
|
|
|
|
|
|
return Task.FromResult(request); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Task<ClientCredentialsTokenRequest> CreateClientCredentialsTokenRequestAsync( |
|
|
|
DiscoveryResponse 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 Task AddParametersToRequestAsync(IdentityClientConfiguration configuration, Request request) |
|
|
|
{ |
|
|
|
foreach (var pair in configuration.Where(p => p.Key.StartsWith("[o]", StringComparison.OrdinalIgnoreCase))) |
|
|
|
{ |
|
|
|
request.Parameters[pair.Key] = pair.Value; |
|
|
|
} |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|