Class: ClientOAuth2Provider

Isolated

Represents the client OAuth2 provider, which is used to generate OAuth2 access tokens using the configured OAuth2 authorization server configurations. This supports the client credentials grant type, password grant type, and the refresh token grant type.

  1. Client Credentials Grant Type
1oauth2:ClientOAuth2Provider provider = new({
2 tokenUrl: "https://localhost:9196/oauth2/token",
3 clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
4 clientSecret: "9205371918321623741",
5 scopes: ["token-scope1", "token-scope2"]
6});
  1. Password Grant Type
1oauth2:ClientOAuth2Provider provider = new({
2 tokenUrl: "https://localhost:9196/oauth2/token/authorize/header",
3 username: "johndoe",
4 password: "A3ddj3w",
5 clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
6 clientSecret: "9205371918321623741",
7 scopes: ["token-scope1", "token-scope2"]
8});
  1. Refresh Token Grant Type
1oauth2:ClientOAuth2Provider provider = new({
2 refreshUrl: "https://localhost:9196/oauth2/token/refresh",
3 refreshToken: "XlfBs91yquexJqDaKEMzVg==",
4 clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
5 clientSecret: "9205371918321623741",
6 scopes: ["token-scope1", "token-scope2"]
7});

Constructor

Provides authentication based on the provided OAuth2 configurations.

init (GrantConfig grantConfig)
  • grantConfig GrantConfig
  • OAuth2 grant type configurations

Methods

generateToken

Get an OAuth2 access token from the authorization server.

generateToken

function generateToken() returns string | Error
Isolated Function

Get an OAuth2 access token from the authorization server.

1string token = check provider.generateToken();

Return Type

(string | Error)

Received OAuth2 access token or else an oauth2:Error if an error occurred