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

Added AbpClaimsServiceOptions #7998

Merged
merged 3 commits into from Mar 9, 2021
Merged

Added AbpClaimsServiceOptions #7998

merged 3 commits into from Mar 9, 2021

Conversation

realLiangshiwei
Copy link
Member

@realLiangshiwei realLiangshiwei commented Mar 9, 2021

It will make custom claims easier

public class MyClaimsPrincipalContributor: IAbpClaimsPrincipalContributor, ITransientDependency
{
    public async Task ContributeAsync(AbpClaimsPrincipalContributorContext context)
    {
        var currentTenant = context.ServiceProvider.GetRequiredService<ICurrentTenant>();
        if (currentTenant.Id != null)
        {
            var tenantStore = context.ServiceProvider.GetRequiredService<ITenantStore>();
            var tenant = await tenantStore.FindAsync(tenantId.Value);
            var claimsIdentity = new ClaimsIdentity();
            claimsIdentity.AddIfNotContains(new Claim("tenantname", tenant.Name));
            context.ClaimsPrincipal.AddIdentity(claimsIdentity);
        }
    }
}

Configure<AbpClaimsServiceOptions>(options=>
{
    options.RequestedClaims.Add("tenantname")
})

@realLiangshiwei realLiangshiwei added this to the 4.3-preview milestone Mar 9, 2021
@maliming maliming marked this pull request as draft March 9, 2021 06:29
@realLiangshiwei realLiangshiwei changed the title Add RequestedClaims to AbpClaimsPrincipalOptions @realLiangshiwei Added AbpClaimsServiceOptions Mar 9, 2021
@realLiangshiwei realLiangshiwei changed the title @realLiangshiwei Added AbpClaimsServiceOptions Added AbpClaimsServiceOptions Mar 9, 2021
@realLiangshiwei realLiangshiwei marked this pull request as ready for review March 9, 2021 06:37
@liquehuo
Copy link

Can you tell me how to use in openiddct ? thank you !
I read this article

@journey191
Copy link

journey191 commented Dec 27, 2023

Hi @realLiangshiwei @maliming
It cannot work in my project(cannot go to function ContributeAsync breakpoints) (ABP ver: 4.3.0)
I'm sure the authentication or other funtions work well, so i have no directions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants