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
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions jwtauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,31 @@ func SetExpiryIn(claims map[string]interface{}, tm time.Duration) {
claims["exp"] = ExpireIn(tm)
}

// 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


// TokenFromCookie tries to retreive the token string from a cookie named
// "jwt".
func TokenFromCookie(r *http.Request) string {
Expand Down