The OAuth2 connector allows you to handle the authentication flow with oauth2 authentication. This can be used in other client connectors which use oauth2 authentication.
- Download the Ballerina tool distribution by navigating https://ballerinalang.org/downloads/
- Extract ballerina-oauth2-0.95.2.zip and copy ballerina-oauth2-0.95.2.jar into the
<ballerina-tools>/bre/lib
folder.
- Use this OAuth2 client connector instead of http client authenticator in other client connectors.
- Obtain the following parameters:
- Access Token
- Client Id
- Client Secret
- Refresh Token
- Refresh Token Endpoint
IMPORTANT: This access token can be used to make API requests on your own account's behalf. Do not share your access token with anyone.
The get action allows to use http get action with oauth2 authentication flow.
- path - The path of the endpoint.
- request - The request message.
The post action allows to use http post action with oauth2 authentication flow.
- path - The path of the endpoint.
- request - The request message.
The put action allows to use http put action with oauth2 authentication flow.
- path - The path of the endpoint.
- request - The request message.
The delete action allows to use http delete action with oauth2 authentication flow.
- path - The path of the endpoint.
- request - The request message.
The patch action allows to use http patch action with oauth2 authentication flow.
- path - The path of the endpoint.
- request - The request message.
- Copy
connector-oauth2/component/samples/oauth2/samples.bal
file and paste it into<ballerina-tools>/bin
folder. - Run the following commands to execute the relevant action.
- get:
bin$ ./ballerina run samples.bal get <baseUrl> <accessToken> <clientId> <clientSecret> <refreshToken> <refreshTokenEP> <path>
- post:
bin$ ./ballerina run samples.bal post <baseUrl> <accessToken> <clientId> <clientSecret> <refreshToken> <refreshTokenEP> <path>
- put:
bin$ ./ballerina run samples.bal put <baseUrl> <accessToken> <clientId> <clientSecret> <refreshToken> <refreshTokenEP> <path>
- delete:
bin$ ./ballerina run samples.bal delete <baseUrl> <accessToken> <clientId> <clientSecret> <refreshToken> <refreshTokenEP> <path>
- patch:
bin$ ./ballerina run samples.bal patch <baseUrl> <accessToken> <clientId> <clientSecret> <refreshToken> <refreshTokenEP> <path>
Note: If you are not passing refresh token in the request, access token won't be refreshed.