mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
joy the admin area works with this commit
This commit is contained in:
parent
4428982052
commit
09126911bd
@ -146,45 +146,25 @@ namespace Ocelot.DependencyInjection
|
||||
var identityServerConfiguration = IdentityServerConfigurationCreator.GetIdentityServerConfiguration();
|
||||
|
||||
if (identityServerConfiguration != null)
|
||||
{
|
||||
services.AddIdentityServer(identityServerConfiguration);
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static void AddIdentityServer(this IServiceCollection services, IIdentityServerConfiguration identityServerConfiguration)
|
||||
{
|
||||
services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
|
||||
services.TryAddSingleton<IHashMatcher, HashMatcher>();
|
||||
var identityServerBuilder = services
|
||||
.AddIdentityServer(options => {
|
||||
options.IssuerUri = "Ocelot";
|
||||
})
|
||||
.AddInMemoryApiResources(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()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.AddInMemoryClients(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
|
||||
}
|
||||
}).AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>();
|
||||
|
||||
.AddIdentityServer()
|
||||
// .AddIdentityServer(options => {
|
||||
// options.IssuerUri = "Ocelot";
|
||||
// })
|
||||
.AddInMemoryApiResources(Resources(identityServerConfiguration))
|
||||
.AddInMemoryClients(Client(identityServerConfiguration))
|
||||
.AddResourceOwnerValidator<OcelotResourceOwnerPasswordValidator>();
|
||||
|
||||
var whb = services.First(x => x.ServiceType == typeof(IWebHostBuilder));
|
||||
var urlFinder = new BaseUrlFinder((IWebHostBuilder)whb.ImplementationInstance);
|
||||
@ -194,13 +174,14 @@ namespace Ocelot.DependencyInjection
|
||||
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
|
||||
.AddIdentityServerAuthentication(o =>
|
||||
{
|
||||
o.Authority = baseSchemeUrlAndPort + "admin";
|
||||
//todo - this needs to come from the config so have to get it in here...
|
||||
o.Authority = baseSchemeUrlAndPort + "/administration";
|
||||
o.ApiName = identityServerConfiguration.ApiName;
|
||||
o.RequireHttpsMetadata = identityServerConfiguration.RequireHttps;
|
||||
//o.AllowedScopes = identityServerConfiguration.AllowedScopes;
|
||||
o.SupportedTokens = SupportedTokens.Both;
|
||||
o.ApiSecret = identityServerConfiguration.ApiSecret;
|
||||
});
|
||||
|
||||
if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword))
|
||||
{
|
||||
identityServerBuilder.AddDeveloperSigningCredential();
|
||||
@ -212,7 +193,62 @@ namespace Ocelot.DependencyInjection
|
||||
}
|
||||
}
|
||||
|
||||
return services;
|
||||
private static List<ApiResource> Resources(IIdentityServerConfiguration identityServerConfiguration)
|
||||
{
|
||||
return new List<ApiResource>
|
||||
{
|
||||
new ApiResource("admin", "My API")
|
||||
};
|
||||
// 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)
|
||||
{
|
||||
return new List<Client>
|
||||
{
|
||||
// resource owner password grant client
|
||||
new Client
|
||||
{
|
||||
ClientId = "admin",
|
||||
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
||||
|
||||
ClientSecrets =
|
||||
{
|
||||
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
|
||||
// }
|
||||
// };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -181,12 +181,12 @@ namespace Ocelot.Middleware
|
||||
|
||||
if(!string.IsNullOrEmpty(configuration.AdministrationPath) && identityServerConfiguration != null)
|
||||
{
|
||||
|
||||
builder.Map(configuration.AdministrationPath, app =>
|
||||
{
|
||||
app.UseMvc();
|
||||
Console.WriteLine("SETTING UP ADMIN AREA");
|
||||
app.UseIdentityServer();
|
||||
app.UseAuthentication();
|
||||
app.UseMvc();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace Ocelot.ManualTest
|
||||
{
|
||||
x.WithMicrosoftLogging(log =>
|
||||
{
|
||||
log.AddConsole(LogLevel.Debug);
|
||||
//log.AddConsole(LogLevel.Debug);
|
||||
})
|
||||
.WithDictionaryHandle();
|
||||
};
|
||||
|
@ -312,6 +312,6 @@
|
||||
|
||||
"GlobalConfiguration": {
|
||||
"RequestIdKey": "OcRequestId",
|
||||
"AdministrationPath": "/admin"
|
||||
"AdministrationPath": "/administration"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user