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

Getting error: java.lang.IllegalStateException: Either 'payload' or 'claims' must be specified. #72

Closed
ExtinctAmoeba opened this issue Dec 17, 2015 · 5 comments

Comments

@ExtinctAmoeba
Copy link

Hi, I'm getting this error:

Getting: java.lang.IllegalStateException: Either 'payload' or 'claims' must be specified.

try {
String s = Jwts.builder().signWith(SignatureAlgorithm.HS256, "61c5fd4007060fd9ed41fc6f2a155a3a47629b9e9b83d75d1c0d97ebb177fa83").compact();
                            Jwts.parser().setSigningKey(s).parseClaimsJws(obj.getString(JSONNodes.json_token));

                            //OK, we can trust this JWT
                            app.getDatabase().beginTransaction();
                            app.user.setToken(obj.getString(JSONNodes.json_token));
                            app.getDatabase().commitTransaction();

                        } catch(SignatureException e) {
                            //Don't trust the JWT! Clear user or handle error messaging
                            app.clearUser();
                        }

What I'm missing or doing wrong?

  1. I need to decode token (empty, there is no data inside, I just need simple token validation) from JSON response.

For example token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE0NTAzNDQ4NDcsImV4cCI6MTQ1MDM0NDkwNywidXNlcl9pZCI6bnVsbCwicmlnaHRzIjpudWxsfQ.p4v00qCakzuMZgLHAlzPB9o0z1DhLz8Ky03fmSaAxcc

@lhazlewood
Copy link
Contributor

This line:

Jwts.builder().signWith(SignatureAlgorithm.HS256, "61c5fd4007060fd9ed41fc6f2a155a3a47629b9e9b83d75d1c0d97ebb177fa83").compact();

Is not signing anything. You've got to specify a payload or a claims to sign in that line.

But that line is specifically for creating tokens. If you already have one, you don't need to do that. Just call the Jwts.parser()... line.

@ExtinctAmoeba
Copy link
Author

Thank You for information. I will try Your suggestion.

@ExtinctAmoeba
Copy link
Author

 try {
            Jwts.parser().setSigningKey(C.TOKENKEY).parse(JWTToken);
        } catch (SignatureException e) {
            //don't trust the JWT!
        }


*Returns me SignatureException: * JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.

What does it mean? And what I'm doing wrong?

@lhazlewood
Copy link
Contributor

use .parseClaimsJws instead of .parse

@lhazlewood
Copy link
Contributor

Closing due to inactivity and no functionality changes discussed. Feel free to re-open if there is something to be done.

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

No branches or pull requests

2 participants