Browse Source

Added Jwt token auth to IDS4 project.

pull/1159/head
Halil ibrahim Kalkan 7 years ago
parent
commit
faa835b58b
  1. 1
      templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs
  2. 2
      templates/service/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj
  3. 13
      templates/service/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs
  4. 4
      templates/service/host/MyCompanyName.MyProjectName.IdentityServer/appsettings.json

1
templates/mvc/src/MyCompanyName.MyProjectName.Web/MyProjectNameWebModule.cs

@ -39,6 +39,7 @@ namespace MyCompanyName.MyProjectName
typeof(AbpIdentityWebModule), typeof(AbpIdentityWebModule),
typeof(AbpAccountWebIdentityServerModule), typeof(AbpAccountWebIdentityServerModule),
typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(AbpTenantManagementWebModule) typeof(AbpTenantManagementWebModule)
)] )]
public class MyProjectNameWebModule : AbpModule public class MyProjectNameWebModule : AbpModule

2
templates/service/host/MyCompanyName.MyProjectName.IdentityServer/MyCompanyName.MyProjectName.IdentityServer.csproj

@ -10,8 +10,10 @@
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> <PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.7.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" /> <PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="2.2.0" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Authentication.JwtBearer\Volo.Abp.AspNetCore.Authentication.JwtBearer.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic\Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.Mvc\Volo.Abp.AspNetCore.Mvc.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" /> <ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AspNetCore.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" />

13
templates/service/host/MyCompanyName.MyProjectName.IdentityServer/MyProjectNameIdentityServerModule.cs

@ -7,6 +7,7 @@ using StackExchange.Redis;
using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Account.Web; using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
@ -51,6 +52,7 @@ namespace MyCompanyName.MyProjectName
typeof(AbpTenantManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementEntityFrameworkCoreModule),
typeof(AbpTenantManagementApplicationModule), typeof(AbpTenantManagementApplicationModule),
typeof(AbpTenantManagementHttpApiModule), typeof(AbpTenantManagementHttpApiModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
typeof(MyProjectNameApplicationContractsModule) typeof(MyProjectNameApplicationContractsModule)
)] )]
public class MyProjectNameIdentityServerModule : AbpModule public class MyProjectNameIdentityServerModule : AbpModule
@ -91,7 +93,15 @@ namespace MyCompanyName.MyProjectName
{ {
options.Applications["MVC"].RootUrl = configuration["AppSelfUrl"]; options.Applications["MVC"].RootUrl = configuration["AppSelfUrl"];
}); });
context.Services.AddAuthentication()
.AddIdentityServerAuthentication(options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = false;
options.ApiName = configuration["AuthServer:ApiName"];
});
context.Services.AddDistributedRedisCache(options => context.Services.AddDistributedRedisCache(options =>
{ {
options.Configuration = configuration["Redis:Configuration"]; options.Configuration = configuration["Redis:Configuration"];
@ -113,6 +123,7 @@ namespace MyCompanyName.MyProjectName
app.UseCorrelationId(); app.UseCorrelationId();
app.UseVirtualFiles(); app.UseVirtualFiles();
app.UseAuthentication(); app.UseAuthentication();
app.UseJwtTokenMiddleware();
if (MultiTenancyConsts.IsEnabled) if (MultiTenancyConsts.IsEnabled)
{ {
app.UseMultiTenancy(); app.UseMultiTenancy();

4
templates/service/host/MyCompanyName.MyProjectName.IdentityServer/appsettings.json

@ -6,6 +6,10 @@
"Redis": { "Redis": {
"Configuration": "127.0.0.1" "Configuration": "127.0.0.1"
}, },
"AuthServer": {
"Authority": "http://localhost:61517/",
"ApiName": "MyProjectName"
},
"IdentityServer": { "IdentityServer": {
"Clients": { "Clients": {
"MyProjectName_Web": { "MyProjectName_Web": {

Loading…
Cancel
Save