@line/bot-sdk
Version:
Node.js SDK for LINE Messaging API
359 lines • 21.6 kB
JavaScript
/**
* Channel Access Token API
* This document describes Channel Access Token API.
*
* The version of the OpenAPI document: 0.0.1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import HTTPFetchClient, { mergeHeaders, } from "../../http-fetch.js";
export class ChannelAccessTokenClient {
httpClient;
/**
* Initializes a new `ChannelAccessTokenClient`.
*
* @param config Configuration for this API client.
* @param config.baseURL The base URL for requests. Defaults to `https://api.line.me`.
* @param config.defaultHeaders Extra headers merged into every request.
*
* @example
* const client = new ChannelAccessTokenClient({
* });
*/
constructor(config) {
const baseURL = config.baseURL || "https://api.line.me";
const defaultHeaders = mergeHeaders(config.defaultHeaders, {});
this.httpClient = new HTTPFetchClient({
defaultHeaders: defaultHeaders,
baseURL: baseURL,
});
}
/**
* Gets all valid channel access token key IDs.
* Calls `GET https://api.line.me/oauth2/v2.1/tokens/kid`.
* To inspect the HTTP status code or response headers, use {@link getsAllValidChannelAccessTokenKeyIdsWithHttpInfo}.
* @param clientAssertionType `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
* @param clientAssertion A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1">LINE Developers documentation</a>
*/
async getsAllValidChannelAccessTokenKeyIds(clientAssertionType, clientAssertion) {
return (await this.getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(clientAssertionType, clientAssertion)).body;
}
/**
* Gets all valid channel access token key IDs.
* Calls `GET https://api.line.me/oauth2/v2.1/tokens/kid`.
* This method returns the response body together with the underlying `httpResponse`.
* @param clientAssertionType `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
* @param clientAssertion A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1">LINE Developers documentation</a>
*/
async getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(clientAssertionType, clientAssertion) {
const queryParams = {
client_assertion_type: clientAssertionType,
client_assertion: clientAssertion,
};
const res = await this.httpClient.get("/oauth2/v2.1/tokens/kid", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Issue short-lived channel access token
* Calls `POST https://api.line.me/v2/oauth/accessToken`.
* To inspect the HTTP status code or response headers, use {@link issueChannelTokenWithHttpInfo}.
* @param grantType `client_credentials`
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token">LINE Developers documentation</a>
*/
async issueChannelToken(grantType, clientId, clientSecret) {
return (await this.issueChannelTokenWithHttpInfo(grantType, clientId, clientSecret)).body;
}
/**
* Issue short-lived channel access token
* Calls `POST https://api.line.me/v2/oauth/accessToken`.
* This method returns the response body together with the underlying `httpResponse`.
* @param grantType `client_credentials`
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token">LINE Developers documentation</a>
*/
async issueChannelTokenWithHttpInfo(grantType, clientId, clientSecret) {
const formParams = {
grant_type: grantType,
client_id: clientId,
client_secret: clientSecret,
};
const res = await this.httpClient.postForm("/v2/oauth/accessToken", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
* Calls `POST https://api.line.me/oauth2/v2.1/token`.
* To inspect the HTTP status code or response headers, use {@link issueChannelTokenByJWTWithHttpInfo}.
* @param grantType client_credentials
* @param clientAssertionType urn:ietf:params:oauth:client-assertion-type:jwt-bearer
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async issueChannelTokenByJWT(grantType, clientAssertionType, clientAssertion) {
return (await this.issueChannelTokenByJWTWithHttpInfo(grantType, clientAssertionType, clientAssertion)).body;
}
/**
* Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
* Calls `POST https://api.line.me/oauth2/v2.1/token`.
* This method returns the response body together with the underlying `httpResponse`.
* @param grantType client_credentials
* @param clientAssertionType urn:ietf:params:oauth:client-assertion-type:jwt-bearer
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async issueChannelTokenByJWTWithHttpInfo(grantType, clientAssertionType, clientAssertion) {
const formParams = {
grant_type: grantType,
client_assertion_type: clientAssertionType,
client_assertion: clientAssertion,
};
const res = await this.httpClient.postForm("/oauth2/v2.1/token", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Issues a new stateless channel access token, which doesn't have max active token limit unlike the other token types. The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* To inspect the HTTP status code or response headers, use {@link issueStatelessChannelTokenWithHttpInfo}.
* @param grantType `client_credentials`
* @param clientAssertionType URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body.
* @deprecated Use {@link issueStatelessChannelTokenByJWTAssertion} or {@link issueStatelessChannelTokenByClientSecret} instead.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelToken(grantType, clientAssertionType, clientAssertion, clientId, clientSecret) {
return (await this.issueStatelessChannelTokenWithHttpInfo(grantType, clientAssertionType, clientAssertion, clientId, clientSecret)).body;
}
/**
* Issues a new stateless channel access token, which doesn't have max active token limit unlike the other token types. The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* This method returns the response body together with the underlying `httpResponse`.
* @param grantType `client_credentials`
* @param clientAssertionType URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @deprecated Use {@link issueStatelessChannelTokenByJWTAssertionWithHttpInfo} or {@link issueStatelessChannelTokenByClientSecretWithHttpInfo} instead.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelTokenWithHttpInfo(grantType, clientAssertionType, clientAssertion, clientId, clientSecret) {
const formParams = {
grant_type: grantType,
client_assertion_type: clientAssertionType,
client_assertion: clientAssertion,
client_id: clientId,
client_secret: clientSecret,
};
if (formParams["grant_type"] === undefined) {
delete formParams["grant_type"];
}
if (formParams["client_assertion_type"] === undefined) {
delete formParams["client_assertion_type"];
}
if (formParams["client_assertion"] === undefined) {
delete formParams["client_assertion"];
}
if (formParams["client_id"] === undefined) {
delete formParams["client_id"];
}
if (formParams["client_secret"] === undefined) {
delete formParams["client_secret"];
}
const res = await this.httpClient.postForm("/oauth2/v3/token", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Revoke short-lived or long-lived channel access token
* Calls `POST https://api.line.me/v2/oauth/revoke`.
* To inspect the HTTP status code or response headers, use {@link revokeChannelTokenWithHttpInfo}.
* @param accessToken A short-lived or long-lived channel access token.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token">LINE Developers documentation</a>
*/
async revokeChannelToken(accessToken) {
return (await this.revokeChannelTokenWithHttpInfo(accessToken)).body;
}
/**
* Revoke short-lived or long-lived channel access token
* Calls `POST https://api.line.me/v2/oauth/revoke`.
* This method returns the response body together with the underlying `httpResponse`.
* @param accessToken A short-lived or long-lived channel access token.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token">LINE Developers documentation</a>
*/
async revokeChannelTokenWithHttpInfo(accessToken) {
const formParams = {
access_token: accessToken,
};
const res = await this.httpClient.postForm("/v2/oauth/revoke", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Revoke channel access token v2.1
* Calls `POST https://api.line.me/oauth2/v2.1/revoke`.
* To inspect the HTTP status code or response headers, use {@link revokeChannelTokenByJWTWithHttpInfo}.
* @param clientId Channel ID
* @param clientSecret Channel Secret
* @param accessToken Channel access token
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async revokeChannelTokenByJWT(clientId, clientSecret, accessToken) {
return (await this.revokeChannelTokenByJWTWithHttpInfo(clientId, clientSecret, accessToken)).body;
}
/**
* Revoke channel access token v2.1
* Calls `POST https://api.line.me/oauth2/v2.1/revoke`.
* This method returns the response body together with the underlying `httpResponse`.
* @param clientId Channel ID
* @param clientSecret Channel Secret
* @param accessToken Channel access token
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async revokeChannelTokenByJWTWithHttpInfo(clientId, clientSecret, accessToken) {
const formParams = {
client_id: clientId,
client_secret: clientSecret,
access_token: accessToken,
};
const res = await this.httpClient.postForm("/oauth2/v2.1/revoke", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Verify the validity of short-lived and long-lived channel access tokens
* Calls `POST https://api.line.me/v2/oauth/verify`.
* To inspect the HTTP status code or response headers, use {@link verifyChannelTokenWithHttpInfo}.
* @param accessToken A short-lived or long-lived channel access token.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token">LINE Developers documentation</a>
*/
async verifyChannelToken(accessToken) {
return (await this.verifyChannelTokenWithHttpInfo(accessToken)).body;
}
/**
* Verify the validity of short-lived and long-lived channel access tokens
* Calls `POST https://api.line.me/v2/oauth/verify`.
* This method returns the response body together with the underlying `httpResponse`.
* @param accessToken A short-lived or long-lived channel access token.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token">LINE Developers documentation</a>
*/
async verifyChannelTokenWithHttpInfo(accessToken) {
const formParams = {
access_token: accessToken,
};
const res = await this.httpClient.postForm("/v2/oauth/verify", formParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
* Calls `GET https://api.line.me/oauth2/v2.1/verify`.
* To inspect the HTTP status code or response headers, use {@link verifyChannelTokenByJWTWithHttpInfo}.
* @param accessToken Channel access token with a user-specified expiration (Channel Access Token v2.1).
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async verifyChannelTokenByJWT(accessToken) {
return (await this.verifyChannelTokenByJWTWithHttpInfo(accessToken)).body;
}
/**
* You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
* Calls `GET https://api.line.me/oauth2/v2.1/verify`.
* This method returns the response body together with the underlying `httpResponse`.
* @param accessToken Channel access token with a user-specified expiration (Channel Access Token v2.1).
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1">LINE Developers documentation</a>
*/
async verifyChannelTokenByJWTWithHttpInfo(accessToken) {
const queryParams = {
access_token: accessToken,
};
const res = await this.httpClient.get("/oauth2/v2.1/verify", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Issues a new stateless channel access token by JWT assertion.
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* To inspect the HTTP status code or response headers, use {@link issueStatelessChannelTokenByJWTAssertionWithHttpInfo}.
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelTokenByJWTAssertion(clientAssertion) {
return this.issueStatelessChannelToken("client_credentials", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", clientAssertion);
}
/**
* Issues a new stateless channel access token by client secret.
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* To inspect the HTTP status code or response headers, use {@link issueStatelessChannelTokenByClientSecretWithHttpInfo}.
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelTokenByClientSecret(clientId, clientSecret) {
return this.issueStatelessChannelToken("client_credentials", undefined, undefined, clientId, clientSecret);
}
/**
* Issues a new stateless channel access token by JWT assertion.
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* This method returns the response body together with the underlying `httpResponse`.
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelTokenByJWTAssertionWithHttpInfo(clientAssertion) {
return this.issueStatelessChannelTokenWithHttpInfo("client_credentials", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", clientAssertion);
}
/**
* Issues a new stateless channel access token by client secret.
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
* Calls `POST https://api.line.me/oauth2/v3/token`.
* This method returns the response body together with the underlying `httpResponse`.
* @param clientId Channel ID.
* @param clientSecret Channel secret.
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
*/
async issueStatelessChannelTokenByClientSecretWithHttpInfo(clientId, clientSecret) {
return this.issueStatelessChannelTokenWithHttpInfo("client_credentials", undefined, undefined, clientId, clientSecret);
}
}
//# sourceMappingURL=channelAccessTokenClient.js.map