Client helper for OAuth2 Token endpoint. Supports "Client Credentials" flow with "client_secret", RS256 JWT "client_assertion", custom grants and token caching.
- Client Credentials Grant (2-Legged OAuth)
- "client_secret" authentication
- "private_key_jwt" authentication method as defined in Assertion Framework for OAuth 2.0 Client Authentication and Authorization Grants and OpenID Connect Core 1.0
- Custom grant support. I.e. for custom assertion grants.
- Access token caching. Uses in-memory cache by default. Caching key includes all parameters, so it is safe to use with more than one Authorization Server, credential set or OAuth scope list.
If you need support for other grant types or authentication methods, please check IdentityModel2.
Install from NuGet:
Install-Package Scalepoint.OAuth.TokenClient
Obtaining access token from Authorization Server token endpoint is as simple as this:
var tokenClient = new ClientCredentialsGrantTokenClient(
tokenEndpointUrl,
new JwtBearerClientAssertionCredentials(
tokenEndpointUrl,
clientId,
x509certificate
)
);
var accessToken = await tokenClient.GetTokenAsync(new [] { scope1, scope2 });
var tokenClient = new ClientCredentialsGrantTokenClient(
tokenEndpointUrl,
new ClientSecretCredentials(
clientId,
clientSecret
)
);
var accessToken = await tokenClient.GetTokenAsync(new [] { scope1, scope2 });
Also check our examples repository example: