Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec#
public class OAuthOptions
{
    public int ClientId { get; set; }
    public List<string> Scopes { get; set; }
    public Uri TokenEndpoint { get; set; }
    public string JsonWebKey { get; set; }
}

//...

private string CreateJwtClientAssertion(OAuthOptions oAuthOptions, Microsoft.IdentityModel.Tokens.JsonWebKey jwk)
{
    var tokenHandler = new JwtSecurityTokenHandler();
    var tokenDescriptor = new SecurityTokenDescriptor
    {
        Expires = DateTime.UtcNow.AddMinutes(960),
        SigningCredentials = new SigningCredentials(jwk, SecurityAlgorithms.RsaSha512Signature),
        Subject = new ClaimsIdentity(new List<Claim>
        {
             new Claim("sub", oAuthOptions.ClientId.ToString()),
            new Claim("iss", oAuthOptions.ClientId.ToString()),
            new Claim("jti", Guid.NewGuid().ToString()),
            new Claim("aud", oAuthOptions.TokenEndpoint.ToString())
            )
        };

    return tokenHandler.WriteToken(tokenHandler.CreateJwtSecurityToken(tokenDescriptor));
}

...