'Validate UserIdentityToken with Javascript

How do i use javascript to validate the token from Office.context.mailbox.getUserIdentityTokenAsync(). Are there any javascript libraries for this?



Solution 1:[1]

Here is documentation on validating an identity token. We do not supply a JS library.

Solution 2:[2]

You can validate the token with a standard Javascript JWT library (like 'jsonwebtoken'). Just read the x509 cert out of the 'amurl' (from the decoded token; decoding can be done with a JWT library as well) and insert it into a PEM format string like this:

  const jwt = require('jsonwebtoken');

  ...

  let token = 'eyJhbG...';
  let amurl_X509Certificate_value = 'MIIGwz...';
  let verify = jwt.verify(
    token,
    [
      '-----BEGIN CERTIFICATE-----',
      amurl_X509Certificate_value,
      '-----END CERTIFICATE-----',
    ].join('\n'),
    { algorithms: ['RS256'] }
  );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Outlook Add-ins Team - MSFT
Solution 2 CK_One