Hi i am trying to generate JWT token using jsrsasign.js library
Below is the code that i am using to generate the token and java code for token validation.By using the below code we are able to generate token and validate also at front end.But when we are passing this token to server for validation its getting failed.
Please provide a solution for me to validate the token at server side.
----------javascript code-------------
// Header
var oHeader = {alg: ‘HS256’, typ: ‘JWT’};
// Payload
var oPayload = {};
var tNow = KJUR.jws.IntDate.get(‘now’);
var tEnd = KJUR.jws.IntDate.get(‘now + 1day’);
oPayload.iss = “http://foo.com”;
oPayload.sub = “mailto:mike@foo.com”;
oPayload.nbf = tNow;
oPayload.iat = tNow;
oPayload.exp = tEnd;
oPayload.jti = “id123456”;
oPayload.aud = “http://foo.com/employee”;
// Sign JWT, password=616161
var sHeader = JSON.stringify(oHeader);
var sPayload = JSON.stringify(oPayload);
var sJWT = KJUR.jws.JWS.sign(“HS256”, sHeader, sPayload, “616161”);
------------Java code to validate the incomming token----------
wts.parser()
.setSigningKey(secretKey)----616161 same as secrete key provided at front end
.parseClaimsJws(token)
.getBody();
You should not be issuing token in your front-end, but assuming that is being done for testing you may want to check the samples at this repository that also show an example for verifying a JWT signed with HS256.