title: Verify Signature with Azure AD
body: <p>I am trying to verify a signature in Azure AD with Java:</p>
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;com.microsoft.azure&lt;/groupId&gt;
    &lt;artifactId&gt;azure-storage&lt;/artifactId&gt;
    &lt;version&gt;8.6.6&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.auth0&lt;/groupId&gt;
    &lt;artifactId&gt;java-jwt&lt;/artifactId&gt;
    &lt;version&gt;3.18.2&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.auth0&lt;/groupId&gt;
    &lt;artifactId&gt;jwks-rsa&lt;/artifactId&gt;
    &lt;version&gt;0.19.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
    &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
    &lt;version&gt;2.12.5&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>And If I try to verify a token, I receive the following error:</p>
  <blockquote>
  <p>The Token's Signature resulted invalid when verified using the
  Algorithm: SHA256withRSA</p>
  </blockquote>
  <p>Applying the following method:</p>
  <pre><code>private boolean verifyJWT(String azureDiscoveryKeys, String token) {
  
      try {
  
          JwkProvider provider = new UrlJwkProvider(new URL(azureDiscoveryKeys));
          DecodedJWT jwt = JWT.decode(token);
          Jwk jwk = provider.get(jwt.getKeyId());
          RSAPublicKey publicKey = (RSAPublicKey) jwk.getPublicKey();
  
          Algorithm alg = Algorithm.RSA256(publicKey, null);
          JWTVerifier verifier = JWT.require(alg).build();
  
          verifier.verify(token);
  
          return true;
      } catch(JWTVerificationException | JwkException | MalformedURLException ex) {
          System.out.println(ex.getMessage());
          return false;
      }
  }
  </code></pre>
  <p>Testing the same method with a token provided by MS ADFS, I am able to verify but with Azure AD, I am not able. How to verify the token to avoid this error? How to adapt the code for Azure AD or to add support for SHA256withRSA? What is wrong in my code?</p>
  <p>Many thanks in advance</p>
  <p>Juan Antonio</p>