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

Are there some methods get encrypt algorithm of a token? #9

Closed
superbogy opened this issue Nov 29, 2018 · 2 comments
Closed

Are there some methods get encrypt algorithm of a token? #9

superbogy opened this issue Nov 29, 2018 · 2 comments
Labels
question Further information is requested

Comments

@superbogy
Copy link

Decode a base64 encode token get the payload info, look like :

{"typ":"JWT","alg":"HS256","jti":"e6ca395f2a6479f9a84739e339544aec"}

Now I want to get the alg: HS256 item of a encode token, How should I do or I need to handle the string by myself?

@gbrlsnchs
Copy link
Owner

gbrlsnchs commented Nov 29, 2018

Since your payload is already decoded, simply unmarshal it to have access to claims and header fields:

var jot jwt.JWT

if err = jwt.Unmarshal(decodedPayload, &jot); err != nil {
    // ...
}

fmt.Println(jot.Algorithm())

Please tell me if this solves your issue. 😄

@gbrlsnchs gbrlsnchs added the question Further information is requested label Nov 29, 2018
@superbogy
Copy link
Author

thank u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants