IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

add extra claims

Open BehnamAbdy opened this issue 9 years ago • 7 comments

i need to add couple of custom extra claims to claims list before sending the response to client (cliams of : job,friend , etc) should i make a custom implementation of IProfileService but dont work public class MyProfileService : IProfileService { public async Task GetProfileDataAsync(ProfileDataRequestContext context) { IEnumerable claims =new List { new Claim(JwtClaimTypes.Role, "admin"), new Claim("claim1", "something") }.Concat(context.Subject.Claims);

        context.AddFilteredClaims(context.Subject.Claims);
    }     
    public Task IsActiveAsync(IsActiveContext context)
    {
        context.IsActive = true;
        return Task.FromResult(0);
    }
}

BehnamAbdy avatar Dec 26 '16 21:12 BehnamAbdy

Did you inject your profile service into pipeline? Like below: builder.Services.AddTransient<IProfileService, MyProfileService >();

atpyk avatar Dec 27 '16 08:12 atpyk

Yes I did it and it works.also breakpoints get hit.but I don't see extra claims on mvcclient user claims

BehnamAbdy avatar Dec 27 '16 17:12 BehnamAbdy

You need to have an ApiResource, like new ApiResource("basicinfo", new []{ JwtClaimTypes.AuthenticationTime } ) , and related it in AllowedScopes in Client. .......... ClientSecrets = { new Secret("secret".Sha256()) }, RequireClientSecret = false, AllowedScopes = new List<string> { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "basicinfo", }

Please try it.

atpyk avatar Dec 28 '16 01:12 atpyk

thank u very much but this dont work, im using identityServer4 rc5 and things are different here

BehnamAbdy avatar Dec 29 '16 05:12 BehnamAbdy

IdentityServer4 v1.0.0 was released last week. I suggest you update to it.

brockallen avatar Dec 29 '16 14:12 brockallen

Im using identity server 4 and have followed the instructions here and for the life of me I cannot get it to hit any breakpoints in the custom profile service.

Yes I registered it at start up

Yes I added claims to the ApiResource

What am i missing?

drowhunter avatar Dec 17 '18 22:12 drowhunter

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 12 '20 15:01 lock[bot]