title: Generate a JWT with an X.509 certificate signature in Powershell
body: <p>I'm trying to get an API access token from Active Directory using certificate authentication as shown here:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow#second-case-access-token-request-with-a-certificate" rel="nofollow noreferrer">Access token request with a certificate</a></p>
  
  <p>The request needs the <strong>client_assertion</strong> property, which is a JWT created from the certificate with the format and specs mentioned here:</p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#assertion-format" rel="nofollow noreferrer">Assertion format</a></p>
  
  <p>Is there a way of generating this token in Powershell that is non-interactive as this is part of a release pipeline?</p>
  
  <p>Edit: To make it a little more clear, this C# code using the <strong>Microsoft.IdentityModel.Clients.ActiveDirectory</strong> library is what I'm trying to do in Powershell, specifically the second line:</p>
  
  <pre><code>AuthenticationContext authContext = new AuthenticationContext(authority);
  
  IClientAssertionCertificate assertion = new ClientAssertionCertificate(clientId, certificate);
  
  authenticationResult = await authContext.AcquireTokenAsync(resource, assertion);
  </code></pre>