|
|
@ -4,6 +4,7 @@ using System.Net.Http; |
|
|
|
using System.Net.Http.Headers; |
|
|
|
using System.Net.Http.Json; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using IdentityModel; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
|
@ -12,17 +13,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost |
|
|
|
public class TokenService : ITokenService |
|
|
|
{ |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
private readonly RemoteAuthenticationOptions _options; |
|
|
|
|
|
|
|
public TokenService(IConfiguration configuration, IOptions<RemoteAuthenticationOptions> options) |
|
|
|
public TokenService(IConfiguration configuration) |
|
|
|
{ |
|
|
|
_configuration = configuration; |
|
|
|
_options = options.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<BaererToken> GetToken() |
|
|
|
{ |
|
|
|
var baseUrl = _configuration["RemoteServices:Default:BaseUrl"]; |
|
|
|
var baseUrl = _configuration["AuthServer:Authority"]; |
|
|
|
var clientId = _configuration["AuthServer:SwaggerClientId"]; |
|
|
|
var clientSecret = _configuration["AuthServer:SwaggerClientSecret"]; |
|
|
|
var grantType = OidcConstants.GrantTypes.ClientCredentials; |
|
|
|
const string routeString = "connect/token"; |
|
|
|
var client = new HttpClient(); |
|
|
|
client.BaseAddress = new Uri(baseUrl); |
|
|
@ -31,11 +33,9 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost |
|
|
|
|
|
|
|
var content = new FormUrlEncodedContent(new[] |
|
|
|
{ |
|
|
|
new KeyValuePair<string, string>("client_id",_options.client_id), |
|
|
|
new KeyValuePair<string, string>("client_secret",_options.client_secret), |
|
|
|
new KeyValuePair<string, string>("grant_type",_options.grant_type), |
|
|
|
new KeyValuePair<string, string>("username",_options.username), |
|
|
|
new KeyValuePair<string, string>("password",_options.password), |
|
|
|
new KeyValuePair<string, string>("client_id",clientId), |
|
|
|
new KeyValuePair<string, string>("client_secret",clientSecret), |
|
|
|
new KeyValuePair<string, string>("grant_type",grantType), |
|
|
|
}); |
|
|
|
|
|
|
|
var response = await client.PostAsync(routeString, content); |
|
|
|