Browse Source

Made sample working.

pull/217/head
Halil İbrahim Kalkan 9 years ago
parent
commit
322a1d5852
  1. 2
      src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj
  2. 33
      src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs
  3. 4
      src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml
  4. 19
      src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs
  5. 2
      src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs

2
src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj

@ -25,9 +25,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Volo.Abp.Account.Web\Volo.Abp.Account.Web.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Http.Client\Volo.Abp.Http.Client.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Identity.Web\Volo.Abp.Identity.Web.csproj" />

33
src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs

@ -2,10 +2,10 @@
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.Azure.KeyVault.WebKey;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@ -13,7 +13,6 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.Account.Web;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.Autofac;
@ -26,19 +25,16 @@ using Volo.Abp.Identity.Web;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.Web;
using Volo.Abp.Permissions;
using Volo.Abp.Permissions.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
namespace MicroserviceDemo.Web
{
[DependsOn(typeof(AbpAutofacModule))]
[DependsOn(typeof(AbpHttpClientModule))]
[DependsOn(typeof(AbpPermissionsEntityFrameworkCoreModule))]
[DependsOn(typeof(AbpIdentityHttpApiModule))]
[DependsOn(typeof(AbpIdentityWebModule))]
[DependsOn(typeof(AbpIdentityEntityFrameworkCoreModule))]
[DependsOn(typeof(AbpAccountWebModule))]
[DependsOn(typeof(AbpMultiTenancyHttpApiClientModule))]
[DependsOn(typeof(AbpMultiTenancyWebModule))]
public class MicroservicesDemoWebModule : AbpModule
@ -82,20 +78,17 @@ namespace MicroserviceDemo.Web
"/Abp/ServiceProxyScript?_v=" + DateTime.Now.Ticks
});
});
var xxx = JwtSecurityTokenHandler.DefaultInboundClaimTypeMap;
//JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); //TODO: Try to understand if this is really needed?
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication(options =>
{
//options.DefaultScheme = IdentityConstants.ApplicationScheme;
//options.DefaultChallengeScheme = "oidc";
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultChallengeScheme = "oidc";
})
//.AddCookie(IdentityConstants.ApplicationScheme)
.AddOpenIdConnect("oidc", options =>
{
//options.SignInScheme = IdentityConstants.ApplicationScheme;
options.SignInScheme = IdentityConstants.ApplicationScheme;
options.Authority = "http://localhost:54307";
options.RequireHttpsMetadata = false;
@ -109,13 +102,21 @@ namespace MicroserviceDemo.Web
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("role");
options.Scope.Add("email");
options.Scope.Add("phone");
options.Scope.Add("multi-tenancy-api");
options.Scope.Add("offline_access");
//options.Scope.Add("offline_access");
options.ClaimActions.MapUniqueJsonKey("email_verified", "email_verified");
options.ClaimActions.MapUniqueJsonKey("phone_number", "phone_number");
options.ClaimActions.MapUniqueJsonKey("phone_number_verified", "phone_number_verified");
options.ClaimActions.MapUniqueJsonKey("role", "role");
options.ClaimActions.MapUniqueJsonKey(AbpClaimTypes.UserName, "name");
options.ClaimActions.MapUniqueJsonKey(AbpClaimTypes.Email, "email");
AbpClaimTypes.UserName = "name";
AbpClaimTypes.Email = "email";
AbpClaimTypes.Role = "role";
AbpClaimTypes.UserId = "sub";
options.SecurityTokenValidator = new MyJwtSecurityTokenHandler();
});

4
src/MicroserviceDemo/MicroserviceDemo.Web/Pages/Index.cshtml

@ -21,9 +21,11 @@
@{
var accessToken = await HttpContextAccessor.HttpContext.GetTokenAsync("access_token");
var refreshToken = await HttpContextAccessor.HttpContext.GetTokenAsync("refresh_token");
}
@accessToken <br />
accessToken = @accessToken <br />
refreshToken = @refreshToken <br />
</abp-card-body>
</abp-card>

19
src/Volo.Abp.Identity.Web/AbpIdentityWebModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Mvc.Localization;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
using Volo.Abp.AutoMapper;
@ -28,8 +29,6 @@ namespace Volo.Abp.Identity.Web
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpIdentityWebModule>();
services.Configure<NavigationOptions>(options =>
{
options.MenuContributors.Add(new AbpIdentityWebMainMenuContributor());
@ -39,7 +38,7 @@ namespace Volo.Abp.Identity.Web
{
options.FileSets.AddEmbedded<AbpIdentityWebModule>("Volo.Abp.Identity.Web");
});
services.Configure<AbpLocalizationOptions>(options =>
{
options.Resources.AddVirtualJson<IdentityResource>("en", "/Localization/Resources/AbpIdentity");
@ -49,6 +48,18 @@ namespace Volo.Abp.Identity.Web
{
options.AddProfile<AbpIdentityWebAutoMapperProfile>(validate: true);
});
services.Configure<RazorPagesOptions>(options =>
{
options.Conventions.AuthorizePage("/Identity/Users/Index", IdentityPermissions.Users.Default);
options.Conventions.AuthorizePage("/Identity/Users/CreateModal", IdentityPermissions.Users.Create);
options.Conventions.AuthorizePage("/Identity/Users/EditModal", IdentityPermissions.Users.Update);
options.Conventions.AuthorizePage("/Identity/Roles/Index", IdentityPermissions.Roles.Default);
options.Conventions.AuthorizePage("/Identity/Roles/CreateModal", IdentityPermissions.Roles.Create);
options.Conventions.AuthorizePage("/Identity/Roles/EditModal", IdentityPermissions.Roles.Update);
});
services.AddAssemblyOf<AbpIdentityWebModule>();
}
}
}

2
src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerBuilderExtensions.cs

@ -31,6 +31,7 @@ namespace Volo.Abp.IdentityServer
AbpClaimTypes.UserId = JwtClaimTypes.Subject;
AbpClaimTypes.UserName = JwtClaimTypes.Name;
AbpClaimTypes.Role = JwtClaimTypes.Role;
AbpClaimTypes.Email = JwtClaimTypes.Email;
}
if (options.UpdateJwtSecurityTokenHandlerDefaultInboundClaimTypeMap)
@ -38,6 +39,7 @@ namespace Volo.Abp.IdentityServer
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserId] = AbpClaimTypes.UserId;
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.UserName] = AbpClaimTypes.UserName;
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Role] = AbpClaimTypes.Role;
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap[AbpClaimTypes.Email] = AbpClaimTypes.Email;
}
return builder;

Loading…
Cancel
Save