Skip to content

Commit 2637f42

Browse files
authored
Channel access token v2.1 support key id (#231)
1 parent d59538e commit 2637f42

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

docs/api-reference/oauth.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class OAuth {
1414
issueChannelAccessTokenV2_1(
1515
client_assertion: string,
1616
): Promise<Types.ChannelAccessToken>
17-
getIssuedChannelAccessTokenV2_1(
17+
getChannelAccessTokenKeyIdsV2_1(
1818
client_assertion: string,
19-
): Promise<{ access_tokens: string[] }>
19+
): Promise<{ key_ids: string[] }>
2020
revokeChannelAccessTokenV2_1(
2121
client_id: string,
2222
client_secret: string,
@@ -66,7 +66,6 @@ It corresponds to the [Issue channel access token](https://developers.line.biz/e
6666
const { access_token, expires_in, token_type } = await oauth.issueAccessToken("client_id", "client_secret");
6767
```
6868

69-
7069
#### `revokeAccessToken(access_token: string): Promise<{}>`
7170

7271
It corresponds to the [Revoke channel access token](https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token) API.
@@ -76,14 +75,13 @@ It corresponds to the [Revoke channel access token](https://developers.line.biz/
7675
await oauth.revokeAccessToken("access_token");
7776
```
7877

79-
8078
#### issueChannelAccessTokenV2_1(client_assertion: string): Promise<Types.ChannelAccessToken>
8179

8280
It corresponds to the [Issue channel access token v2.1](https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1) API.
8381

84-
#### getIssuedChannelAccessTokenV2_1(client_assertion: string): Promise<{ access_tokens: string[] }>
82+
#### getChannelAccessTokenKeyIdsV2_1(client_assertion: string): Promise<{ key_ids: string[] }>
8583

86-
It corresponds to the [Get Issued channel access token v2.1](https://developers.line.biz/en/reference/messaging-api/#get-issued-channel-access-tokens-v2-1) API.
84+
It corresponds to the [Get all valid channel access token key IDs v2.1](https://developers.line.biz/en/reference/messaging-api/#get-all-issued-channel-access-token-key-ids-v2-1) API.
8785

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

lib/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,10 @@ export class OAuth {
627627
});
628628
}
629629

630-
public getIssuedChannelAccessTokenV2_1(
630+
public getChannelAccessTokenKeyIdsV2_1(
631631
client_assertion: string,
632-
): Promise<{ access_tokens: string[] }> {
633-
return this.http.get(`${OAUTH_BASE_PREFIX_V2_1}/tokens`, {
632+
): Promise<{ key_ids: string[] }> {
633+
return this.http.get(`${OAUTH_BASE_PREFIX_V2_1}/tokens/kid`, {
634634
client_assertion_type:
635635
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
636636
client_assertion,

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,7 @@ export type ChannelAccessToken = {
24302430
access_token: string;
24312431
expires_in: number;
24322432
token_type: "Bearer";
2433+
key_id?: string;
24332434
};
24342435

24352436
/**

test/client.spec.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,6 @@ describe("oauth", () => {
902902
afterEach(() => nock.cleanAll());
903903
after(() => nock.enableNetConnect());
904904

905-
const accessTokenReply = {
906-
access_token: "access_token",
907-
expires_in: 2592000,
908-
token_type: "Bearer",
909-
};
910-
911905
const interceptionOption = {
912906
reqheaders: {
913907
"content-type": "application/x-www-form-urlencoded",
@@ -916,19 +910,25 @@ describe("oauth", () => {
916910
};
917911

918912
it("issueAccessToken", async () => {
919-
const client_id = "test_client_id",
920-
client_secret = "test_client_secret";
913+
const client_id = "test_client_id";
914+
const client_secret = "test_client_secret";
915+
const reply = {
916+
access_token: "access_token",
917+
expires_in: 2592000,
918+
token_type: "Bearer",
919+
};
920+
921921
const scope = nock(OAUTH_BASE_PREFIX, interceptionOption)
922922
.post("/accessToken", {
923923
grant_type: "client_credentials",
924924
client_id,
925925
client_secret,
926926
})
927-
.reply(200, accessTokenReply);
927+
.reply(200, reply);
928928

929929
const res = await oauth.issueAccessToken(client_id, client_secret);
930930
equal(scope.isDone(), true);
931-
deepEqual(res, accessTokenReply);
931+
deepEqual(res, reply);
932932
});
933933

934934
it("revokeAccessToken", async () => {
@@ -944,6 +944,12 @@ describe("oauth", () => {
944944

945945
it("issueChannelAccessTokenV2_1", async () => {
946946
const client_assertion = "client_assertion";
947+
const reply = {
948+
access_token: "access_token",
949+
expires_in: 2592000,
950+
token_type: "Bearer",
951+
key_id: "key_id",
952+
};
947953

948954
const scope = nock(OAUTH_BASE_PREFIX_V2_1, interceptionOption)
949955
.post("/token", {
@@ -952,31 +958,31 @@ describe("oauth", () => {
952958
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
953959
client_assertion,
954960
})
955-
.reply(200, accessTokenReply);
961+
.reply(200, reply);
956962

957963
const res = await oauth.issueChannelAccessTokenV2_1(client_assertion);
958964
equal(scope.isDone(), true);
959-
deepEqual(res, accessTokenReply);
965+
deepEqual(res, reply);
960966
});
961967

962-
it("getIssuedChannelAccessTokenV2_1", async () => {
968+
it("getChannelAccessTokenKeyIdsV2_1", async () => {
963969
const client_assertion = "client_assertion";
964-
const accessTokenReply = {
965-
access_tokens: ["test_access_tokens"],
970+
const reply = {
971+
key_ids: ["key_id"],
966972
};
967973

968974
const scope = nock(OAUTH_BASE_PREFIX_V2_1)
969-
.get("/tokens")
975+
.get("/tokens/kid")
970976
.query({
971977
client_assertion_type:
972978
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
973979
client_assertion,
974980
})
975-
.reply(200, accessTokenReply);
981+
.reply(200, reply);
976982

977-
const res = await oauth.getIssuedChannelAccessTokenV2_1(client_assertion);
983+
const res = await oauth.getChannelAccessTokenKeyIdsV2_1(client_assertion);
978984
equal(scope.isDone(), true);
979-
deepEqual(res, accessTokenReply);
985+
deepEqual(res, reply);
980986
});
981987

982988
it("revokeChannelAccessTokenV2_1", async () => {

0 commit comments

Comments
 (0)