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 more methods from RFC 7519 standard. #80

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DroidZed
Copy link

@DroidZed DroidZed commented Sep 5, 2023

I find it kinda annoying to not have a helper method for the other fields found in RFC 7519 registered claims section, even if it's a one liner for each part, I really thought it would be helpful to add these methods and make our lives n lines less painful.

@DroidZed DroidZed changed the title Added setSub to the library Added more methods from RFC 7519 standard. Sep 6, 2023
jwtauth.go Outdated
Comment on lines 241 to 264
// Set subject ("sub") in the claims
func setSub(claims map[string]interface{}, sub string) {
claims["sub"] = sub
}

// Set audience ("aud") in the claims
func setAudience(claims map[string]interface{}, aud string) {
claims["aud"] = aud
}

// Set JWT ID ("jti") in the claims
func setJwtId(claims map[string]interface{}, jti string) {
claims["jti"] = jti
}

// Set not Before ("nbf") in the claims
func setNotBefore(claims map[string]interface{}, nbf time.Time) {
claims["nbf"] = nbf.UTC().Unix()
}

// Add custom additional claim in the claims (For private/public claims, RFC 7519)
func setXClaim(claims map[string]interface{}, claimName string, claimValue interface{}) {
claims[claimName] = claimValue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these new functions are not exported, what's the point of adding it to the codebase?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the new edits

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

Successfully merging this pull request may close these issues.

None yet

2 participants