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
Revert Encoding/Decoding changes for better compatibility #117
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
08b2b96
Revert Encoding/Decoding changes for better compatibility
ajermaky 5838617
Revert encoding changes and keep decoding
ajermaky d7f2c46
Update Decode Segment and add test case to parser
ajermaky 25379bc
Switching to utilizing global var
ajermaky edf4019
Small changes
ajermaky 7cc0ea7
Revert atomic changes to utilize boolean
ajermaky f7e4a4f
Remove setter and export variable directly
ajermaky e3e7b46
Add example cognito token alongside public key
ajermaky 9eac92d
Update names
ajermaky 03aa267
More name changes
ajermaky File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,14 @@ import ( | |
"time" | ||
) | ||
|
||
|
||
// DecodePaddingAllowed will switch the codec used for encoding/decoding JWTs respectively. Note that the JWS RFC7515 | ||
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. It is only used for decoding, not encoding 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. done |
||
// states that the tokens will utilize a Base64url encoding with no padding. Unfortunately, some implementations | ||
// of JWT are producing non-standard tokens, and thus require support for decoding. Note that this is a global | ||
// variable, and updating it will change the behavior on a package level, and is also NOT go-routine safe. | ||
// To use the non-recommended decoding, set this boolean to `true` prior to using this package. | ||
var DecodePaddingAllowed bool | ||
|
||
// TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time). | ||
// You can override it to use another time value. This is useful for testing or if your | ||
// server uses a different time zone than your tokens. | ||
|
@@ -112,5 +120,12 @@ func EncodeSegment(seg []byte) string { | |
// Deprecated: In a future release, we will demote this function to a non-exported function, since it | ||
// should only be used internally | ||
func DecodeSegment(seg string) ([]byte, error) { | ||
if DecodePaddingAllowed { | ||
if l := len(seg) % 4; l > 0 { | ||
seg += strings.Repeat("=", 4-l) | ||
} | ||
return base64.URLEncoding.DecodeString(seg) | ||
} | ||
|
||
return base64.RawURLEncoding.DecodeString(seg) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you think we can toss in the example JWT token from this comment?
#92 (comment)
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.
Just added! Note that I had to add the public key to the repo, added a note where we reference it.