This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Object - oauth2 : OutboundOAuth2Provider

Represents the outbound OAuth2 provider, which generates OAtuh2 tokens. This supports the client credentials grant type, password grant type, and the direct token mode, which sends the access token directly. The oauth2:OutboundOAuth2Provider is an implementation of the auth:OutboundAuthProvider interface.

  1. Client Credentials Grant Type
 oauth2:OutboundOAuth2Provider oauth2Provider1 = new({
     tokenUrl: "https://localhost:9196/oauth2/token",
     clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
     clientSecret: "9205371918321623741",
     scopes: ["token-scope1", "token-scope2"]
 });
  1. Password Grant Type
 oauth2:OutboundOAuth2Provider oauth2Provider5 = new({
     tokenUrl: "https://localhost:9196/oauth2/token/authorize/header",
     username: "johndoe",
     password: "A3ddj3w",
     clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
     clientSecret: "9205371918321623741",
     scopes: ["token-scope1", "token-scope2"]
 });
  1. Direct Token Mode
 oauth2:OutboundOAuth2Provider oauth2Provider13 = new({
     accessToken: "2YotnFZFEjr1zCsicMWpAA",
     refreshConfig: {
         refreshUrl: "https://localhost:9196/oauth2/token/refresh",
         refreshToken: "XlfBs91yquexJqDaKEMzVg==",
         clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L",
         clientSecret: "9205371918321623741",
         scopes: ["token-scope1", "token-scope2"]
     }
 });

Constructor

__init

(GrantTypeConfig? oauth2ProviderConfig)

  • oauth2ProviderConfig GrantTypeConfig? ()
  • Outbound OAuth2 provider configurations

Methods

Generate a token for the OAuth2 authentication.

Inspects the incoming data and generates the token for the OAuth2 authentication.

Fields

  • oauth2ProviderConfig GrantTypeConfig?
  • Outbound OAuth2 provider configurations

generateToken

()

returns string | Error

Generate a token for the OAuth2 authentication.

 string:auth:Error token = outboundOAuth2Provider.generateToken();
  • Return Type

    (string | Error)
  • Generated string token or else an auth:Error if an error occurred

inspect

(map<anydata> data)

returns string | Error | ()

Inspects the incoming data and generates the token for the OAuth2 authentication.

 string:auth:Error? token = outboundOAuth2Provider.inspect(data);

Parameters

  • data map<anydata>
  • Map of data, which is extracted from the HTTP response

  • Return Type

    (string | Error | ())
  • Generated string token, an auth:Error occurred while generating the token, or else () if nothing is to be returned