more changes to get admin area working...few todos left in and some properties that we are no longer setting on scopes and resources does this matter?

This commit is contained in:
Tom Gardham-Pallister 2017-10-25 08:16:21 +01:00
parent 09126911bd
commit 24c018721f

View File

@ -159,13 +159,11 @@ namespace Ocelot.DependencyInjection
services.TryAddSingleton<IHashMatcher, HashMatcher>(); services.TryAddSingleton<IHashMatcher, HashMatcher>();
var identityServerBuilder = services var identityServerBuilder = services
.AddIdentityServer() .AddIdentityServer()
// .AddIdentityServer(options => {
// options.IssuerUri = "Ocelot";
// })
.AddInMemoryApiResources(Resources(identityServerConfiguration)) .AddInMemoryApiResources(Resources(identityServerConfiguration))
.AddInMemoryClients(Client(identityServerConfiguration)) .AddInMemoryClients(Client(identityServerConfiguration))
.AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>(); .AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>();
//todo - refactor a method so we know why this is happening
var whb = services.First(x => x.ServiceType == typeof(IWebHostBuilder)); var whb = services.First(x => x.ServiceType == typeof(IWebHostBuilder));
var urlFinder = new BaseUrlFinder((IWebHostBuilder)whb.ImplementationInstance); var urlFinder = new BaseUrlFinder((IWebHostBuilder)whb.ImplementationInstance);
var baseSchemeUrlAndPort = urlFinder.Find(); var baseSchemeUrlAndPort = urlFinder.Find();
@ -182,12 +180,14 @@ namespace Ocelot.DependencyInjection
o.ApiSecret = identityServerConfiguration.ApiSecret; o.ApiSecret = identityServerConfiguration.ApiSecret;
}); });
//todo - refactor naming..
if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword)) if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword))
{ {
identityServerBuilder.AddDeveloperSigningCredential(); identityServerBuilder.AddDeveloperSigningCredential();
} }
else else
{ {
//todo - refactor so calls method?
var cert = new X509Certificate2(identityServerConfiguration.CredentialsSigningCertificateLocation, identityServerConfiguration.CredentialsSigningCertificatePassword); var cert = new X509Certificate2(identityServerConfiguration.CredentialsSigningCertificateLocation, identityServerConfiguration.CredentialsSigningCertificatePassword);
identityServerBuilder.AddSigningCredential(cert); identityServerBuilder.AddSigningCredential(cert);
} }
@ -197,58 +197,31 @@ namespace Ocelot.DependencyInjection
{ {
return new List<ApiResource> return new List<ApiResource>
{ {
new ApiResource("admin", "My API") new ApiResource(identityServerConfiguration.ApiName, identityServerConfiguration.ApiName)
{
ApiSecrets = new List<Secret>
{
new Secret
{
Value = identityServerConfiguration.ApiSecret.Sha256()
}
}
}
}; };
// return new List<ApiResource>
// {
// new ApiResource
// {
// Name = identityServerConfiguration.ApiName,
// Description = identityServerConfiguration.Description,
// Enabled = identityServerConfiguration.Enabled,
// DisplayName = identityServerConfiguration.ApiName,
// Scopes = identityServerConfiguration.AllowedScopes.Select(x => new Scope(x)).ToList(),
// ApiSecrets = new List<Secret>
// {
// new Secret
// {
// Value = identityServerConfiguration.ApiSecret.Sha256()
// }
// }
// }
// };
} }
private static List<Client> Client(IIdentityServerConfiguration identityServerConfiguration) private static List<Client> Client(IIdentityServerConfiguration identityServerConfiguration)
{ {
return new List<Client> return new List<Client>
{ {
// resource owner password grant client
new Client new Client
{ {
ClientId = "admin", ClientId = identityServerConfiguration.ApiName,
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets = new List<Secret> {new Secret(identityServerConfiguration.ApiSecret.Sha256())},
ClientSecrets = AllowedScopes = { identityServerConfiguration.ApiName }
{
new Secret("secret".Sha256())
},
AllowedScopes = { "admin" }
} }
}; };
// return new List<Client>
// {
// new Client
// {
// ClientId = identityServerConfiguration.ApiName,
// AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
// ClientSecrets = new List<Secret> {new Secret(identityServerConfiguration.ApiSecret.Sha256())},
// AllowedScopes = identityServerConfiguration.AllowedScopes,
// AccessTokenType = identityServerConfiguration.AccessTokenType,
// Enabled = identityServerConfiguration.Enabled,
// RequireClientSecret = identityServerConfiguration.RequireClientSecret
// }
// };
} }
} }
} }