UNPKG

14.3 kBJavaScriptView Raw
1/**
2 * Channel Access Token API
3 * This document describes Channel Access Token API.
4 *
5 * The version of the OpenAPI document: 0.0.1
6 *
7 *
8 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9 * https://openapi-generator.tech
10 * Do not edit the class manually.
11 */
12import * as Types from "../../types.js";
13import HTTPFetchClient from "../../http-fetch.js";
14export class ChannelAccessTokenClient {
15 httpClient;
16 constructor(config) {
17 const baseURL = config.baseURL || "https://api.line.me";
18 this.httpClient = new HTTPFetchClient({
19 defaultHeaders: {},
20 baseURL: baseURL,
21 });
22 }
23 async parseHTTPResponse(response) {
24 const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
25 let resBody = {
26 ...(await response.json()),
27 };
28 if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
29 resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME);
30 }
31 return resBody;
32 }
33 /**
34 * Gets all valid channel access token key IDs.
35 * @param clientAssertionType `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
36 * @param clientAssertion A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
37 *
38 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1"> Documentation</a>
39 */
40 async getsAllValidChannelAccessTokenKeyIds(clientAssertionType, clientAssertion) {
41 return (await this.getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(clientAssertionType, clientAssertion)).body;
42 }
43 /**
44 * Gets all valid channel access token key IDs..
45 * This method includes HttpInfo object to return additional information.
46 * @param clientAssertionType `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
47 * @param clientAssertion A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
48 *
49 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1"> Documentation</a>
50 */
51 async getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(clientAssertionType, clientAssertion) {
52 const queryParams = {
53 clientAssertionType: clientAssertionType,
54 clientAssertion: clientAssertion,
55 };
56 Object.keys(queryParams).forEach((key) => {
57 if (queryParams[key] === undefined) {
58 delete queryParams[key];
59 }
60 });
61 const res = await this.httpClient.get("/oauth2/v2.1/tokens/kid", queryParams);
62 return { httpResponse: res, body: await res.json() };
63 }
64 /**
65 * Issue short-lived channel access token
66 * @param grantType `client_credentials`
67 * @param clientId Channel ID.
68 * @param clientSecret Channel secret.
69 *
70 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token"> Documentation</a>
71 */
72 async issueChannelToken(grantType, clientId, clientSecret) {
73 return (await this.issueChannelTokenWithHttpInfo(grantType, clientId, clientSecret)).body;
74 }
75 /**
76 * Issue short-lived channel access token.
77 * This method includes HttpInfo object to return additional information.
78 * @param grantType `client_credentials`
79 * @param clientId Channel ID.
80 * @param clientSecret Channel secret.
81 *
82 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token"> Documentation</a>
83 */
84 async issueChannelTokenWithHttpInfo(grantType, clientId, clientSecret) {
85 const formParams = {
86 grant_type: grantType,
87 client_id: clientId,
88 client_secret: clientSecret,
89 };
90 Object.keys(formParams).forEach((key) => {
91 if (formParams[key] === undefined) {
92 delete formParams[key];
93 }
94 });
95 const res = await this.httpClient.postForm("/v2/oauth/accessToken", formParams);
96 return { httpResponse: res, body: await res.json() };
97 }
98 /**
99 * Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
100 * @param grantType client_credentials
101 * @param clientAssertionType urn:ietf:params:oauth:client-assertion-type:jwt-bearer
102 * @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
103 *
104 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1"> Documentation</a>
105 */
106 async issueChannelTokenByJWT(grantType, clientAssertionType, clientAssertion) {
107 return (await this.issueChannelTokenByJWTWithHttpInfo(grantType, clientAssertionType, clientAssertion)).body;
108 }
109 /**
110 * Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication..
111 * This method includes HttpInfo object to return additional information.
112 * @param grantType client_credentials
113 * @param clientAssertionType urn:ietf:params:oauth:client-assertion-type:jwt-bearer
114 * @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
115 *
116 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1"> Documentation</a>
117 */
118 async issueChannelTokenByJWTWithHttpInfo(grantType, clientAssertionType, clientAssertion) {
119 const formParams = {
120 grant_type: grantType,
121 client_assertion_type: clientAssertionType,
122 client_assertion: clientAssertion,
123 };
124 Object.keys(formParams).forEach((key) => {
125 if (formParams[key] === undefined) {
126 delete formParams[key];
127 }
128 });
129 const res = await this.httpClient.postForm("/oauth2/v2.1/token", formParams);
130 return { httpResponse: res, body: await res.json() };
131 }
132 /**
133 * 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.
134 * @param grantType `client_credentials`
135 * @param clientAssertionType URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
136 * @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
137 * @param clientId Channel ID.
138 * @param clientSecret Channel secret.
139 *
140 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token"> Documentation</a>
141 */
142 async issueStatelessChannelToken(grantType, clientAssertionType, clientAssertion, clientId, clientSecret) {
143 return (await this.issueStatelessChannelTokenWithHttpInfo(grantType, clientAssertionType, clientAssertion, clientId, clientSecret)).body;
144 }
145 /**
146 * 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. .
147 * This method includes HttpInfo object to return additional information.
148 * @param grantType `client_credentials`
149 * @param clientAssertionType URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
150 * @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
151 * @param clientId Channel ID.
152 * @param clientSecret Channel secret.
153 *
154 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token"> Documentation</a>
155 */
156 async issueStatelessChannelTokenWithHttpInfo(grantType, clientAssertionType, clientAssertion, clientId, clientSecret) {
157 const formParams = {
158 grant_type: grantType,
159 client_assertion_type: clientAssertionType,
160 client_assertion: clientAssertion,
161 client_id: clientId,
162 client_secret: clientSecret,
163 };
164 Object.keys(formParams).forEach((key) => {
165 if (formParams[key] === undefined) {
166 delete formParams[key];
167 }
168 });
169 const res = await this.httpClient.postForm("/oauth2/v3/token", formParams);
170 return { httpResponse: res, body: await res.json() };
171 }
172 /**
173 * Revoke short-lived or long-lived channel access token
174 * @param accessToken Channel access token
175 *
176 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token"> Documentation</a>
177 */
178 async revokeChannelToken(accessToken) {
179 return (await this.revokeChannelTokenWithHttpInfo(accessToken)).body;
180 }
181 /**
182 * Revoke short-lived or long-lived channel access token.
183 * This method includes HttpInfo object to return additional information.
184 * @param accessToken Channel access token
185 *
186 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token"> Documentation</a>
187 */
188 async revokeChannelTokenWithHttpInfo(accessToken) {
189 const formParams = {
190 access_token: accessToken,
191 };
192 Object.keys(formParams).forEach((key) => {
193 if (formParams[key] === undefined) {
194 delete formParams[key];
195 }
196 });
197 const res = await this.httpClient.postForm("/v2/oauth/revoke", formParams);
198 return { httpResponse: res, body: await res.json() };
199 }
200 /**
201 * Revoke channel access token v2.1
202 * @param clientId Channel ID
203 * @param clientSecret Channel Secret
204 * @param accessToken Channel access token
205 *
206 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1"> Documentation</a>
207 */
208 async revokeChannelTokenByJWT(clientId, clientSecret, accessToken) {
209 return (await this.revokeChannelTokenByJWTWithHttpInfo(clientId, clientSecret, accessToken)).body;
210 }
211 /**
212 * Revoke channel access token v2.1.
213 * This method includes HttpInfo object to return additional information.
214 * @param clientId Channel ID
215 * @param clientSecret Channel Secret
216 * @param accessToken Channel access token
217 *
218 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1"> Documentation</a>
219 */
220 async revokeChannelTokenByJWTWithHttpInfo(clientId, clientSecret, accessToken) {
221 const formParams = {
222 client_id: clientId,
223 client_secret: clientSecret,
224 access_token: accessToken,
225 };
226 Object.keys(formParams).forEach((key) => {
227 if (formParams[key] === undefined) {
228 delete formParams[key];
229 }
230 });
231 const res = await this.httpClient.postForm("/oauth2/v2.1/revoke", formParams);
232 return { httpResponse: res, body: await res.json() };
233 }
234 /**
235 * Verify the validity of short-lived and long-lived channel access tokens
236 * @param accessToken A short-lived or long-lived channel access token.
237 *
238 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token"> Documentation</a>
239 */
240 async verifyChannelToken(accessToken) {
241 return (await this.verifyChannelTokenWithHttpInfo(accessToken)).body;
242 }
243 /**
244 * Verify the validity of short-lived and long-lived channel access tokens.
245 * This method includes HttpInfo object to return additional information.
246 * @param accessToken A short-lived or long-lived channel access token.
247 *
248 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token"> Documentation</a>
249 */
250 async verifyChannelTokenWithHttpInfo(accessToken) {
251 const formParams = {
252 access_token: accessToken,
253 };
254 Object.keys(formParams).forEach((key) => {
255 if (formParams[key] === undefined) {
256 delete formParams[key];
257 }
258 });
259 const res = await this.httpClient.postForm("/v2/oauth/verify", formParams);
260 return { httpResponse: res, body: await res.json() };
261 }
262 /**
263 * You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
264 * @param accessToken Channel access token with a user-specified expiration (Channel Access Token v2.1).
265 *
266 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1"> Documentation</a>
267 */
268 async verifyChannelTokenByJWT(accessToken) {
269 return (await this.verifyChannelTokenByJWTWithHttpInfo(accessToken)).body;
270 }
271 /**
272 * You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid..
273 * This method includes HttpInfo object to return additional information.
274 * @param accessToken Channel access token with a user-specified expiration (Channel Access Token v2.1).
275 *
276 * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-channel-access-token-v2-1"> Documentation</a>
277 */
278 async verifyChannelTokenByJWTWithHttpInfo(accessToken) {
279 const queryParams = {
280 accessToken: accessToken,
281 };
282 Object.keys(queryParams).forEach((key) => {
283 if (queryParams[key] === undefined) {
284 delete queryParams[key];
285 }
286 });
287 const res = await this.httpClient.get("/oauth2/v2.1/verify", queryParams);
288 return { httpResponse: res, body: await res.json() };
289 }
290}
291//# sourceMappingURL=channelAccessTokenClient.js.map
\No newline at end of file