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

How to add additional claims to the token? #53

Open
BenjamenMeyer opened this issue Feb 16, 2024 · 3 comments
Open

How to add additional claims to the token? #53

BenjamenMeyer opened this issue Feb 16, 2024 · 3 comments

Comments

@BenjamenMeyer
Copy link

Services often need to add their own claims to tokens to manage what users are allowed to do in a system. OIDC providers like Okta, Auth0, and others allow their users to add claims via configuration and integrations to support this. How can this be done with mockoidc? One can decode the access token to get the claims.

I tried building a custom user object:

type myUserObject struct {
    mockoidc.MockUser
    PhoneVerified bool
}

with the Claims() method adding the additional data to the jwt.Claims, but I still only get the original data - nothing in the way of the custom claims I added.

What am I missing?

@BenjamenMeyer
Copy link
Author

I created my own jsonClaims type that JSON encodes all the fields based on mockoidc's mockClaims type which adds the additional field which is what is used by my implementation of Claims().

@BenjamenMeyer
Copy link
Author

PR #54 has some example code that exemplifies the behavior in a similar pattern to how I was doing it in my other code. The PR creates a custom user with a new attribute (PhoneVerified) and then adds a test to the session to get a token with the custom user type and checks for the attribute being in the claims as one would expect. The new test presently fails.

@akosyakov
Copy link

I stumbled over the same, would be nice to have easier way adding new claims.

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

No branches or pull requests

2 participants