Skip to content

SamhammerAG/OAuth2Authenticator

Repository files navigation

OAuth2Authenticator

ci

OAuth2 client for obtaining and refreshing of access tokens.

Nuget Package

Currently supported grant types

Setup

Initialize the client service in the application startup. 

public void ConfigureServices(IServiceCollection services)
{
    services.InitOAuth2Authenticator();
}

Usage

OAuth2Authenticator

This class holds the request logic for all OAuth2 grant types. Injectable over the IOAuth2Authenticator interface.

private readonly IOAuth2Authenticator _authenticator;

await _authenticator.PasswordGrant(url, clientId, username, password);

await _authenticator.RefreshTokenGrant(url, clientId, refreshToken);

await _authenticator.ClientCredentialsGrant(url, clientId, clientSecret);

After the request, a OAuth2TokenResponse or null returns.

OAuth2TokenHandler

This class holds common logic which is needed for token handling. Injectable over the IOAuth2TokenHandler interface.

private readonly IOAuth2TokenHandler _handler;

await _handler.RefreshHandler(token, url, clientId, Func<...> /*To get a new token*/, threshold));

OAuth2TokenResponseExtension

Checks if the token request was successful.

token.Successful()

Checks that the token is not expired.

token.Valid()

API Reference