Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create middleware for claims map. Make it configurable. #3975

Closed
maliming opened this issue May 16, 2020 · 0 comments · Fixed by #3985
Closed

Create middleware for claims map. Make it configurable. #3975

maliming opened this issue May 16, 2020 · 0 comments · Fixed by #3985
Assignees
Milestone

Comments

@maliming
Copy link
Member

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();
});
@maliming maliming self-assigned this May 16, 2020
@maliming maliming added this to the 2.8 milestone May 16, 2020
maliming added a commit that referenced this issue May 17, 2020
@maliming maliming mentioned this issue May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant