I want to build a payload for JWT token which uses iat and exp in header. I understand this date is in seconds. How can I get this date in apigee.
Can I used system.timestamp and divide by 1000 ?
Solved! Go to Solution.
Can I used system.timestamp and divide by 1000 (to get a time value in seconds)
yes, you can.
I want to build a payload for JWT token which uses iat and exp in header.
ok I've got a couple comments for you.
My advice is (a) to be thoughtful about re-purposing payload claims and moving them to the header with the same or similar meaning. It will lead to confusion and probably maintenance problems down the road. and (b) consider using the GenerateJWT policy to do the right thing for iat and exp.
example policy to generate a JWT with an iat and exp claim:
<GenerateJWT name='gjwt-1'>
<Algorithm>RS256</Algorithm>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<PrivateKey>
<Value ref="private.key"/>
<Id ref='private-key-id'/>
</PrivateKey>
<Subject ref="jwt_subject" />
<ExpiresIn>1h</ExpiresIn> <!-- expires in 1 hour -->
</GenerateJWT>
Can I used system.timestamp and divide by 1000 (to get a time value in seconds)
yes, you can.
I want to build a payload for JWT token which uses iat and exp in header.
ok I've got a couple comments for you.
My advice is (a) to be thoughtful about re-purposing payload claims and moving them to the header with the same or similar meaning. It will lead to confusion and probably maintenance problems down the road. and (b) consider using the GenerateJWT policy to do the right thing for iat and exp.
example policy to generate a JWT with an iat and exp claim:
<GenerateJWT name='gjwt-1'>
<Algorithm>RS256</Algorithm>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<PrivateKey>
<Value ref="private.key"/>
<Id ref='private-key-id'/>
</PrivateKey>
<Subject ref="jwt_subject" />
<ExpiresIn>1h</ExpiresIn> <!-- expires in 1 hour -->
</GenerateJWT>
My bad.. I want to use it in payload only. Header will be as per standard.