<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668625#M4752891</link>
    <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;carlos.roggan&lt;/SPAN&gt; - I could verify in MTX scenario . &lt;/P&gt;</description>
    <pubDate>Wed, 17 May 2023 10:45:32 GMT</pubDate>
    <dc:creator>sreehari_vpillai</dc:creator>
    <dc:date>2023-05-17T10:45:32Z</dc:date>
    <item>
      <title>Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaq-p/12668620</link>
      <description>&lt;P&gt;Hi , &lt;/P&gt;
  &lt;P&gt;I have an application deployed in Cloud Foundry and has an xsuaa instance bound. Using post man , I generated an access token using client id and client secret. And I get the token . I could decode the token in jwt.io website ( to say that token is in good order ) . &lt;/P&gt;
  &lt;P&gt;Now, Can I verify the token programmatically outside the cloud foundry , if I have the verification key from xsuaa ?&lt;/P&gt;I tried this way 
  &lt;BR /&gt;
  &lt;BR /&gt;
  &lt;UL&gt;
   &lt;LI&gt;Created a .pem file , copying the verification key &lt;/LI&gt;
  &lt;/UL&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2167823-screenshot-2023-05-15-at-51133-pm.png" /&gt;&lt;/P&gt;
  &lt;UL&gt;
   &lt;LI&gt;replaced \n with actual new lines. &lt;/LI&gt;
   &lt;LI&gt;Put the code together &lt;/LI&gt;
  &lt;/UL&gt;
  &lt;PRE&gt;&lt;CODE&gt;const fs = require("fs");
const jwt = require("jsonwebtoken");

var cert = fs.readFileSync('public.pem','utf8');

var token = '&amp;lt;token from postman&amp;gt;';
jwt.verify(token, cert, function (err, decoded,) {
    //goes to error says "invalid signature"
    console.log(err);
});&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;It always goes to "invalid signature" error.&lt;/P&gt;
  &lt;P&gt;What could've gone wrong ? &lt;/P&gt;
  &lt;P&gt;Sreehari &lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 13:26:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaq-p/12668620</guid>
      <dc:creator>sreehari_vpillai</dc:creator>
      <dc:date>2023-05-15T13:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668621#M4752887</link>
      <description>&lt;P&gt;Hello   &lt;SPAN class="mention-scrubbed"&gt;sreehari.vpillai&lt;/SPAN&gt; &lt;BR /&gt;I've done the following:&lt;BR /&gt;Create service instance of xsuaa&lt;BR /&gt;Create service key&lt;BR /&gt;View service key&lt;BR /&gt;Copy service key into node app (shortened below)&lt;BR /&gt;Then use below code.&lt;BR /&gt;The code uses xssec to fetch a token programmatically (instead of using postman)&lt;BR /&gt;Then use the public key which is provided in the credentials (service key) for verification.&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;BR /&gt;Cheers,&lt;BR /&gt;Carlos&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const jsonwebtoken = require("jsonwebtoken");const xssec = require('@sap/xssec');&lt;BR /&gt;const CREDENTIALS = {
   "clientid": "sb-na-62b4996f-21bd-4c6b-85f7-dac24e36af1b!t78007",
   "clientsecret": "V6YgP5fkfqn5r2UCojs=",
   "url": "https://mysubdomain.authentication.eu.hana.ondemand.com",
   "verificationkey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr9ApOgCp/7GuctK/dcyJ\nBaFK2Uzhh7RkVsp1Sfg04u6a6ewZEhlPrdlD/+QfdetBzaDbIXyQf37JQjL/z2YD\RFrFP7b/d0k82ImSmOTwAUBhnB/BR/UERNUnPpbfGICBRkL8AmnDYm/\nWpYUDOk65Xj0kiCe4Pqi5S6I/CLTpXVf6gxrxVSojBYib9VlEDTBORdcxRpwSAEF\nMwIDAQAB\n-----END PUBLIC KEY-----"}


xssec.requests.requestClientCredentialsToken(null, CREDENTIALS, null, null, (err, token)=&amp;gt;{
   jsonwebtoken.verify(token, CREDENTIALS.verificationkey, (err, decoded) =&amp;gt; {
      console.log("client id: " + decoded.cid)   
   })
})&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 May 2023 14:52:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668621#M4752887</guid>
      <dc:creator>CarlosRoggan</dc:creator>
      <dc:date>2023-05-15T14:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668622#M4752888</link>
      <description>&lt;P&gt;My bad. It was a multi tenancy shared xsuaa instance. I token was generated with the auth URL of consumer , and verified with verification key of provider ( what else would I have access to anyway ) . I generated one with provider auth api , and verified. &lt;/P&gt;&lt;P&gt;both your way and my way worked. thanks mate &lt;/P&gt;</description>
      <pubDate>Mon, 15 May 2023 16:51:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668622#M4752888</guid>
      <dc:creator>sreehari_vpillai</dc:creator>
      <dc:date>2023-05-15T16:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668623#M4752889</link>
      <description>&lt;P&gt;Have you tried this in multi tenancy mode ? What verification token shall we use , if the token is issued by the consumer ? Any additional input to be passed while verifying the token ? &lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 05:22:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668623#M4752889</guid>
      <dc:creator>sreehari_vpillai</dc:creator>
      <dc:date>2023-05-16T05:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668624#M4752890</link>
      <description>&lt;P&gt;To try the code snippet, I just created a service instance, no MT app.&lt;BR /&gt;The verification key is contained in the binding information.&lt;/P&gt;&lt;P&gt;To get the verification key at runtime, you can take it from the JKU: &lt;/P&gt;&lt;P&gt;When you introspect the JWT token, you have the required information in the JWT header:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;{&lt;BR /&gt;  "alg": "RS256",&lt;BR /&gt; "jku": "https://rsubdomain.authentication.eu.hana.ondemand.com/token_keys",&lt;BR /&gt;  "kid": "default-jwt-key--19292961",&lt;BR /&gt;  "typ": "JWT"&lt;BR /&gt;  "jid": "xvW3li3J7RiMcjiYmvnkGE4NWKp84="&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using the key id (kid) you can find the correct key in the JKU Url&lt;/P&gt;&lt;P&gt;Kind Regards, &lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:02:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668624#M4752890</guid>
      <dc:creator>CarlosRoggan</dc:creator>
      <dc:date>2023-05-16T07:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Verify xsuaa generated JWT , using nodejs jsonwebtoken package</title>
      <link>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668625#M4752891</link>
      <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;carlos.roggan&lt;/SPAN&gt; - I could verify in MTX scenario . &lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2023 10:45:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/verify-xsuaa-generated-jwt-using-nodejs-jsonwebtoken-package/qaa-p/12668625#M4752891</guid>
      <dc:creator>sreehari_vpillai</dc:creator>
      <dc:date>2023-05-17T10:45:32Z</dc:date>
    </item>
  </channel>
</rss>

