Browse Source

Revise IDS4 configuration

pull/1156/head
Halil ibrahim Kalkan 7 years ago
parent
commit
e0b379f124
  1. 62
      templates/mvc/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs
  2. 6
      templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs
  3. 3
      templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json
  4. 2
      templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
  5. 12
      templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json
  6. 10
      templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs
  7. 5
      templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json
  8. 7
      templates/mvc/src/MyCompanyName.MyProjectName.Web/appsettings.json
  9. 2
      templates/mvc/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/appsettings.json

62
templates/mvc/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeeder.cs → templates/mvc/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Configuration;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
@ -12,26 +14,29 @@ using Volo.Abp.Uow;
namespace MyCompanyName.MyProjectName.IdentityServer
{
public class IdentityServerDataSeeder : IDataSeedContributor, ITransientDependency
public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransientDependency
{
private readonly IApiResourceRepository _apiResourceRepository;
private readonly IClientRepository _clientRepository;
private readonly IIdentityResourceDataSeeder _identityResourceDataSeeder;
private readonly IGuidGenerator _guidGenerator;
private readonly IPermissionDataSeeder _permissionDataSeeder;
private readonly IConfigurationAccessor _configurationAccessor;
public IdentityServerDataSeeder(
public IdentityServerDataSeedContributor(
IClientRepository clientRepository,
IApiResourceRepository apiResourceRepository,
IIdentityResourceDataSeeder identityResourceDataSeeder,
IGuidGenerator guidGenerator,
IPermissionDataSeeder permissionDataSeeder)
IPermissionDataSeeder permissionDataSeeder,
IConfigurationAccessor configurationAccessor)
{
_clientRepository = clientRepository;
_apiResourceRepository = apiResourceRepository;
_identityResourceDataSeeder = identityResourceDataSeeder;
_guidGenerator = guidGenerator;
_permissionDataSeeder = permissionDataSeeder;
_configurationAccessor = configurationAccessor;
}
[UnitOfWork]
@ -98,23 +103,38 @@ namespace MyCompanyName.MyProjectName.IdentityServer
"MyProjectName"
};
/* MyProjectName_Web client is only needed if you created a tiered
* solution. Otherwise, delete this client. */
await CreateClientAsync(
"MyProjectName_Web",
commonScopes,
new[] { "hybrid" },
commonSecret,
redirectUri: "https://localhost:44314/signin-oidc",
postLogoutRedirectUri: "https://localhost:44314/signout-callback-oidc"
);
await CreateClientAsync(
"MyCompanyName_ConsoleTestApp",
commonScopes,
new[] { "password", "client_credentials" },
commonSecret
);
var configurationSection = _configurationAccessor.Configuration.GetSection("IdentityServer:Clients");
//Web Client
var webClientId = configurationSection["MyProjectName_Web:ClientId"];
if (!webClientId.IsNullOrWhiteSpace())
{
var webClientRootUrl = configurationSection["MyProjectName_Web:RootUrl"].EnsureEndsWith('/');
/* MyProjectName_Web client is only needed if you created a tiered
* solution. Otherwise, you can delete this client. */
await CreateClientAsync(
webClientId,
commonScopes,
new[] { "hybrid" },
commonSecret,
redirectUri: $"{webClientRootUrl}signin-oidc",
postLogoutRedirectUri: $"{webClientRootUrl}signout-callback-oidc"
);
}
//Console Test Client
var consoleClientId = configurationSection["MyProjectName_ConsoleTestApp:ClientId"];
if (!consoleClientId.IsNullOrWhiteSpace())
{
await CreateClientAsync(
consoleClientId,
commonScopes,
new[] { "password", "client_credentials" },
commonSecret
);
}
}
private async Task<Client> CreateClientAsync(

6
templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs

@ -33,7 +33,7 @@ namespace MyCompanyName.MyProjectName
var hostingEnvironment = context.Services.GetHostingEnvironment();
ConfigureConventionalControllers();
ConfigureAuthentication(context);
ConfigureAuthentication(context, configuration);
ConfigureSwagger(context);
ConfigureLocalization();
ConfigureVirtualFileSystem(context);
@ -64,12 +64,12 @@ namespace MyCompanyName.MyProjectName
});
}
private void ConfigureAuthentication(ServiceConfigurationContext context)
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfigurationRoot configuration)
{
context.Services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = "https://localhost:44348";
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = true;
options.ApiName = "MyProjectName";
});

3
templates/mvc/src/MyCompanyName.MyProjectName.HttpApi.Host/appsettings.json

@ -4,5 +4,8 @@
},
"Redis": {
"Configuration": "127.0.0.1"
},
"AuthServer": {
"Authority": "https://localhost:44348"
}
}

2
templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs

@ -77,7 +77,7 @@ namespace MyCompanyName.MyProjectName
Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].RootUrl = "https://localhost:44348/";
options.Applications["MVC"].RootUrl = configuration["AppSelfUrl"];
});
Configure<BackgroundJobOptions>(options =>

12
templates/mvc/src/MyCompanyName.MyProjectName.IdentityServer/appsettings.json

@ -1,8 +1,20 @@
{
"AppSelfUrl": "https://localhost:44348",
"ConnectionStrings": {
"Default": "Server=localhost;Database=MyProjectName;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Redis": {
"Configuration": "127.0.0.1"
},
"IdentityServer": {
"Clients": {
"MyProjectName_Web": {
"ClientId": "MyProjectName_Web",
"RootUrl": "https://localhost:44314/"
},
"MyProjectName_ConsoleTestApp": {
"ClientId": "MyProjectName_ConsoleTestApp"
}
}
}
}

10
templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/MyProjectNameWebModule.cs

@ -69,7 +69,7 @@ namespace MyCompanyName.MyProjectName
var configuration = context.Services.GetConfiguration();
ConfigureUrls(configuration);
ConfigureAuthentication(context);
ConfigureAuthentication(context, configuration);
ConfigureAutoMapper();
ConfigureVirtualFileSystem(hostingEnvironment);
ConfigureNavigationServices();
@ -90,7 +90,7 @@ namespace MyCompanyName.MyProjectName
Configure<MultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsMultiTenancyEnabled; });
}
private void ConfigureAuthentication(ServiceConfigurationContext context)
private void ConfigureAuthentication(ServiceConfigurationContext context, IConfigurationRoot configuration)
{
context.Services.AddAuthentication(options =>
{
@ -104,12 +104,12 @@ namespace MyCompanyName.MyProjectName
})
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:44348";
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = true;
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.ClientId = "MyProjectName_Web";
options.ClientSecret = "1q2w3e*";
options.ClientId = configuration["AuthServer:ClientId"];
options.ClientSecret = configuration["AuthServer:ClientSecret"];
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;

5
templates/mvc/src/MyCompanyName.MyProjectName.Web.Host/appsettings.json

@ -7,5 +7,10 @@
},
"Redis": {
"Configuration": "127.0.0.1"
},
"AuthServer": {
"Authority": "https://localhost:44348",
"ClientId": "MyProjectName_Web",
"ClientSecret": "1q2w3e*"
}
}

7
templates/mvc/src/MyCompanyName.MyProjectName.Web/appsettings.json

@ -5,5 +5,12 @@
},
"AuthServer": {
"Authority": "https://localhost:44361"
},
"IdentityServer": {
"Clients": {
"MyProjectName_ConsoleTestApp": {
"ClientId": "MyProjectName_ConsoleTestApp"
}
}
}
}

2
templates/mvc/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/appsettings.json

@ -7,7 +7,7 @@
"IdentityClients": {
"Default": {
"GrantType": "password",
"ClientId": "MyCompanyName_ConsoleTestApp",
"ClientId": "MyProjectName_ConsoleTestApp",
"ClientSecret": "1q2w3e*",
"UserName": "admin",
"UserPassword": "1q2w3E*",

Loading…
Cancel
Save