-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
AGENT-950: Implement Separate JWT Tokens for Different User Personas #9039
Changes from all commits
a189a7d
fe60214
58f798c
dd4713b
7a3528b
60d37d0
e2e19d2
e45f4d6
b346e46
f7aa520
fcbc5af
4185056
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,22 +9,33 @@ import ( | |
"github.com/pkg/errors" | ||
) | ||
|
||
// UserAuthHeaderWriter sets the JWT authorization token. | ||
func UserAuthHeaderWriter(token string) runtime.ClientAuthInfoWriter { | ||
// WatcherAuthHeaderWriter sets the JWT authorization token. | ||
func WatcherAuthHeaderWriter(token string) runtime.ClientAuthInfoWriter { | ||
return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { | ||
return r.SetHeaderParam("Authorization", token) | ||
return r.SetHeaderParam("Watcher-Authorization", token) | ||
}) | ||
} | ||
|
||
// ParseExpirationFromToken checks if the token is expired or not. | ||
func ParseExpirationFromToken(tokenString string) (time.Time, error) { | ||
// ParseToken checks if the token string is valid or not and returns JWT token claim. | ||
func ParseToken(tokenString string) (jwt.MapClaims, error) { | ||
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{}) | ||
if err != nil { | ||
return time.Time{}, err | ||
return nil, err | ||
} | ||
claims, ok := token.Claims.(jwt.MapClaims) | ||
if !ok { | ||
return time.Time{}, errors.Errorf("malformed token claims in url") | ||
return nil, errors.Errorf("malformed token claims in url") | ||
} | ||
return claims, nil | ||
} | ||
|
||
// ParseExpirationFromToken checks if the token is expired or not. | ||
// Returns zero time on error for consistent return type; caller should ignore time on error. | ||
// Otherwise returns the token expiry time. | ||
func ParseExpirationFromToken(tokenString string) (time.Time, error) { | ||
claims, err := ParseToken(tokenString) | ||
if err != nil { | ||
return time.Time{}, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm missing something but I wonder why its necessary to return time on a failure since it seems to be unused on failure in gencrypto/authconfig.go. If its needed please add a comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the comments |
||
} | ||
exp, ok := claims["exp"].(float64) | ||
if !ok { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PATCH doesn't need the ${authz} token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes for
PATCH
got added here via rebase and originally came from a commit on Sep 30 i.e. faaddc1 however I think its a wrong commit becausePATCH
is not used in any curl requests in installer repo. The correct use is in appliance here and hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, for now the appliance isn't directly using the code (the func was copied to the codebase instead).
Will probably be handled later on to reuse this func, so I think it'd be safer to update the PATCH flow as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will update the
PATCH
flow here(even if its unused now). Please note , later in the appliance, you will need to pass theUSER_AUTH_TOKEN