<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.im
        {mso-style-name:im;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">My 2 cents:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">There is an openSSL example to verify a jwt:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><a href="https://gist.github.com/rolandyoung/176dd310a6948e094be6">https://gist.github.com/rolandyoung/176dd310a6948e094be6</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">By using jose4j<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> // be sure you do not have any EOL at the end of the token<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">String accesToken = …;<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">accesToken = accesToken.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"\r\n"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">accesToken = accesToken.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"\n"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">JsonWebSignature
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> JsonWebSignature();</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.setCompactSerialization(accesToken);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">jws</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.setKey(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">publicKey</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">boolean signatureVerified = jws.verifySignature();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">To get a PublicKey : if you put the content of the realm public you get from keycloak admin
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">public</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> PublicKey
<span style="background:silver;mso-highlight:silver">getPublicKey</span>(String </span>
<span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">) {</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">File
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> File(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt;text-autospace:none"><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">try</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> (FileInputStream
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">fis</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> FileInputStream(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);
<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:36.0pt;text-autospace:none">
<span style="font-size:8.0pt;font-family:"Courier New";color:black">DataInputStream
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> DataInputStream(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">fis</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);)
{</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">byte</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">[]
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">byte</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">[(</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">int</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">)
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">f</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.length()];</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.readFully(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">dis</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.close();<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> // convert to der format<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> String pem = new String(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">keyBytes</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"-----BEGIN (.*)-----"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"-----END (.*)----"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"\r\n"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">pem</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.replaceAll(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"\n"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">""</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New""> byte[] der = Base64.getDecoder().decode(pem); // java 8<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:black">X509EncodedKeySpec
</span><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">spec</span><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:black"> =
</span><b><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:black"> X509EncodedKeySpec(der);</span><span lang="FR" style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="FR" style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">KeyFactory
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">kf</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> = KeyFactory.<i>getInstance</i>(</span><b><i><span style="font-size:8.0pt;font-family:"Courier New";color:#0000C0">RSA</span></i></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">return</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">kf</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">.generatePublic(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">spec</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> }
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">catch</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> (IOException | InvalidKeySpecException | NoSuchAlgorithmException
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">e</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">) {</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">throw</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black">
</span><b><span style="font-size:8.0pt;font-family:"Courier New";color:#7F0055">new</span></b><span style="font-size:8.0pt;font-family:"Courier New";color:black"> RuntimeException(</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"Failed
to load public key from file '"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> +
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">fileName</span><span style="font-size:8.0pt;font-family:"Courier New";color:black"> +
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#2A00FF">"'"</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">,
</span><span style="font-size:8.0pt;font-family:"Courier New";color:#6A3E3E">e</span><span style="font-size:8.0pt;font-family:"Courier New";color:black">);</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> }</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:"Courier New";color:black"> }</span><span style="font-size:8.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">With Java 8, it is quite simple too<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">String[] tokenParts</span><span style="font-size:8.0pt;font-family:"Calibri","sans-serif";color:#1F497D"> =
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">accessToken.split("\\.");</span><span style="font-size:8.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">// detect algo from tokenParts[0] or put "SHA256withRSA” (for “RS256”)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Calibri","sans-serif";color:#1F497D">
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">String jwtSignAlgo = "SHA256withRSA";
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E"> String jwtInputString = tokenParts[0] + “.” + tokenParts[1];<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E"> String jwtDecodedSign = new String(Base64.getUrlDecoder().decode(tokenParts[2]);</span><span style="font-size:8.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">
</span><span lang="FR" style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">Signature verifier = Signature.getInstance(jwtSignAlgo);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="FR" style="font-size:8.0pt;font-family:Consolas;color:black">
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.initVerify(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">publicKey</span><span style="font-size:8.0pt;font-family:Consolas;color:black">);</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black">
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.update(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">jwtInputString</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.getBytes("UTF-8"));</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:8.0pt;font-family:Consolas;color:black"> boolean
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">signatureVerified</span><span style="font-size:8.0pt;font-family:Consolas;color:black"> =
</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">verifier</span><span style="font-size:8.0pt;font-family:Consolas;color:black">.verify(</span><span style="font-size:8.0pt;font-family:Consolas;color:#6A3E3E">jwtDecodedSign</span><span style="font-size:8.0pt;font-family:Consolas;color:black">);</span><span style="font-size:8.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">gerard<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> keycloak-user-bounces@lists.jboss.org [mailto:keycloak-user-bounces@lists.jboss.org]
<b>On Behalf Of </b>Stian Thorgersen<br>
<b>Sent:</b> vendredi 6 mai 2016 07:33<br>
<b>To:</b> Aikeaguinea<br>
<b>Cc:</b> keycloak-user<br>
<b>Subject:</b> Re: [keycloak-user] Validating JWT tokens<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 4 May 2016 at 18:37, Aikeaguinea <<a href="mailto:aikeaguinea@xsmail.com" target="_blank">aikeaguinea@xsmail.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Figured it out, kinda. I have to use the Realm public key, and at least<br>
in <a href="http://jwt.io" target="_blank">jwt.io</a> it has to begin with "-----BEGIN PUBLIC KEY-----" and end with<br>
"-----END PUBLIC KEY-----" -- these can't be omitted.<br>
<br>
If I try using the Realm certificate, it won't work, however, whether or<br>
not I use "-----BEGIN CERTIFICATE-----"/"-----END CERTIFICATE-----".<br>
<br>
If I use the validator at <a href="http://kjur.github.io/jsjws/tool_jwt.html" target="_blank">
http://kjur.github.io/jsjws/tool_jwt.html</a> and<br>
select "default X509 Certificate (RSA z4) it tells me "Error: malformed<br>
X.509 certificate PEM (code:003)"<br>
<br>
I can use the Realm public key for validating the JWT, but shouldn't the<br>
certificate work as well?<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The certificate is only used by SAML, so no you can't verify the JWT with the certificate only the public key.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal"><br>
<span class="im">On Wed, May 4, 2016, at 12:00 PM, Aikeaguinea wrote:</span><br>
<span class="im">> I have a client with a service account and credentials using Signed Jwt.</span><br>
<span class="im">> Authentication works fine. The service uses</span><br>
<span class="im">> org.keycloak.adapters.authentication.ClientCredentialsProviderUtils#setClientCredentials</span><br>
<span class="im">> to create the JWT token and set the headers, and I get back a JWT</span><br>
<span class="im">> containing an access token from Keycloak.</span><br>
<span class="im">></span><br>
<span class="im">> However, when I use <a href="http://jwt.io" target="_blank">jwt.io</a> to look at the access token, I can't validate</span><br>
<span class="im">> the signature. This is true whether I use the client Certificate (from</span><br>
<span class="im">> the client's Credentials tab), the Realm public key, or the Realm</span><br>
<span class="im">> Certificate. In addition, I have generated the client's public key from</span><br>
<span class="im">> the certificate using</span><br>
<span class="im">></span><br>
<span class="im">> keytool -exportcert -alias x -keypass y -storepass z -rfc -keystore</span><br>
<span class="im">> client-keystore.jks | openssl x509 -inform pem -pubkey</span><br>
<span class="im">></span><br>
<span class="im">> on the jks file supplied when I generated the client credentials, and</span><br>
<span class="im">> that doesn't work either.</span><br>
<span class="im">></span><br>
<span class="im">> We've also been having trouble validating the signature programmatically</span><br>
<span class="im">> using Java.</span><br>
<span class="im">></span><br>
<span class="im">> Any idea why I might be seeing this?</span><br>
<span class="im">></span><br>
<span class="im">> --</span><br>
<span class="im">> <a href="http://www.fastmail.com" target="_blank">http://www.fastmail.com</a> - Or how I learned to stop worrying and</span><br>
<span class="im">> love email again</span><br>
<span class="im">></span><br>
<br>
<br>
<span class="hoenzb"><span style="color:#888888">--</span></span><span style="color:#888888"><br>
<span class="hoenzb"> Aikeaguinea</span><br>
<span class="hoenzb"> <a href="mailto:aikeaguinea@xsmail.com">aikeaguinea@xsmail.com</a></span><br>
<br>
<span class="hoenzb">--</span><br>
<span class="hoenzb"><a href="http://www.fastmail.com" target="_blank">http://www.fastmail.com</a> - Send your email first class</span></span><o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><br>
_______________________________________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>