Hi All,

Shall we use Nimbus libraryto generate JWT in API Manager?

Currently, we are generating the token without any standard libraries which
leads to errors like [2] and [3].

For the JIRA [3], currently we are having following code snippet to
create x5t header.

byte[] digestInBytes = digestValue.digest();
String publicCertThumbprint = hexify(digestInBytes);
String base64EncodedThumbPrint = Base64Utils.encode(
publicCertThumbprint.getBytes());

But, We have to use in the following way inorder to fix by ourself

byte[] digestInBytes = digestValue.digest();
String base64EncodedThumbPrint;
base64EncodedThumbPrint = Base64Utils.encode(digestInBytes);
base64EncodedThumbPrint = base64EncodedThumbPrint.split("=")[0]; // Remove
any trailing '='s
base64EncodedThumbPrint = base64EncodedThumbPrint.replace('+', '-'); //
62nd char of encoding
base64EncodedThumbPrint = base64EncodedThumbPrint.replace('/', '_'); //
63rd char of encoding
return base64EncodedThumbPrint;

If we are using Nimbus, we can use JWSHeader.Builder [4] to generate JWT
Headers like

JWSHeader header = new JWSHeader.Builder(JWSAlgorithm.HS256).
                    contentType("text/plain").
                    customParam("exp", new Date().getTime()).
                    build();

We can add custom headers too. Appriciate your input on this.

[1] : http://connect2id.com/products/nimbus-jose-jwt
[2] : https://wso2.org/jira/browse/APIMANAGER-4117
[3] : https://wso2.org/jira/browse/APIMANAGER-2922
[4] :
http://static.javadoc.io/com.nimbusds/nimbus-jose-jwt/4.5/com/nimbusds/jose/JWSHeader.Builder.html

-- 
Thanks
Abimaran Kugathasan

Software Engineer | WSO2 Inc
Data & APIs Technologies Team
Mobile : +94 773922820

<http://stackoverflow.com/users/515034>
<http://lk.linkedin.com/in/abimaran>  <http://www.lkabimaran.blogspot.com/>
<https://github.com/abimarank>  <https://twitter.com/abimaran>
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to