|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
@ -44,14 +47,6 @@ namespace IdentityService.Host
|
|
|
|
|
options.Authority = configuration["AuthServer:Authority"];
|
|
|
|
|
options.ApiName = configuration["AuthServer:ApiName"];
|
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
|
//TODO: Should create an extension method for that (may require to create a new ABP package depending on the IdentityServer4.AccessTokenValidation)
|
|
|
|
|
//options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified;
|
|
|
|
|
//options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
context.Services.AddSwaggerGen(options =>
|
|
|
|
@ -95,6 +90,22 @@ namespace IdentityService.Host
|
|
|
|
|
app.UseVirtualFiles();
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
|
|
|
|
|
app.Use(async (ctx, next) =>
|
|
|
|
|
{
|
|
|
|
|
var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>();
|
|
|
|
|
var map = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{ "sub", AbpClaimTypes.UserId },
|
|
|
|
|
{ "role", AbpClaimTypes.Role },
|
|
|
|
|
{ "email", AbpClaimTypes.Email },
|
|
|
|
|
//any other map
|
|
|
|
|
};
|
|
|
|
|
var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList();
|
|
|
|
|
currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer))));
|
|
|
|
|
await next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.UseAbpRequestLocalization(); //TODO: localization?
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(options =>
|
|
|
|
|