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

Customizable JWT Claims #166

Open
ilhesam opened this issue Jan 20, 2023 · 0 comments · May be fixed by #167
Open

Customizable JWT Claims #166

ilhesam opened this issue Jan 20, 2023 · 0 comments · May be fixed by #167
Assignees
Milestone

Comments

@ilhesam
Copy link
Collaborator

ilhesam commented Jan 20, 2023

Currently, The JWT claims are generating in JwtTokenService and these are not customizable for the end-developers.
We should solve this issue with the Decorator pattern.
So, we will have an interface for the JWT claim decorators and we will implement a manager to handle decoration:

public interface IUserJwtClaimsDecorator<TUser>
{
    IEnumerable<Claim> GetClaims(TUser user);
}

public class UserJwtClaimsManager<TUser>
{
    protected readonly IEnumerable<IUserJwtClaimsDecorator<TUser>> Decorators;

    public UserJwtClaimsManager(IEnumerable<IUserJwtClaimsDecorator<TUser>> decorators)
    {
        Decorators = decorators;
    }

    public IEnumerable<Claim> GetClaims()
    {
        var result = new List<Claim>();

        foreach (var decorator in Decorators)
        {
            var claims = decorator.GetClaims(user);

            result.AddRange(claims);
        }

        return result;
    }
}

Finally, we should implement a default decorator and we will use UserJwtClaimsManager in JwtTokenService

As a developer, I can implement IUserJwtClaimsDecorator and add my JWT claims.

@ilhesam ilhesam added the Issue label Jan 20, 2023
@ilhesam ilhesam added this to the Milestone 1 milestone Jan 20, 2023
@ilhesam ilhesam self-assigned this Jan 20, 2023
@ilhesam ilhesam linked a pull request Jan 20, 2023 that will close this issue
@ilhesam ilhesam linked a pull request Jan 20, 2023 that will close this issue
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