# new OAuth()

OAuth is a class representing OAuth APIs. It provides methods corresponding to messaging APIs (opens new window).

# Type signature

class OAuth {
  constructor() {}

  issueAccessToken(client_id: string, client_secret: string): Promise<Types.ChannelAccessToken>
  revokeAccessToken(access_token: string): Promise<{}>
  issueChannelAccessTokenV2_1(
    client_assertion: string,
  ): Promise<Types.ChannelAccessToken>
  getChannelAccessTokenKeyIdsV2_1(
    client_assertion: string,
  ): Promise<{ key_ids: string[] }>
  revokeChannelAccessTokenV2_1(
    client_id: string,
    client_secret: string,
    access_token: string,
  ): Promise<{}>
}

# Create a OAuth

The OAuth class is provided by the main module.

// CommonJS
const { OAuth } = require('@line/bot-sdk');

// ES6 modules or TypeScript
import { OAuth } from '@line/bot-sdk';

To create a client instance:

const oauth = new OAuth();

And now you can call client functions as usual:

const { access_token } = await oauth.issueAccessToken("client_id", "client_secret");

# Methods

For functions returning Promise, there will be errors thrown if something goes wrong, such as HTTP errors or parsing errors. You can catch them with the .catch() method of the promises. The detailed error handling is explained in the Client guide.

# OAuth

# issueAccessToken(client_id: string, client_secret: string): Promise<Types.ChannelAccessToken>

It corresponds to the Issue channel access token (opens new window) API.

const { access_token, expires_in, token_type } = await oauth.issueAccessToken("client_id", "client_secret");

# revokeAccessToken(access_token: string): Promise<{}>

It corresponds to the Revoke channel access token (opens new window) API.

await oauth.revokeAccessToken("access_token");

# issueChannelAccessTokenV2_1(client_assertion: string): Promise<Types.ChannelAccessToken>

It corresponds to the Issue channel access token v2.1 (opens new window) API.

# getChannelAccessTokenKeyIdsV2_1(client_assertion: string): Promise<{ key_ids: string[] }>

It corresponds to the Get all valid channel access token key IDs v2.1 (opens new window) API.

# revokeChannelAccessTokenV2_1(client_id: string, client_secret: string, access_token: string): Promise<{}>

It corresponds to the Revoke channel access token v2.1 (opens new window) API.