Skip to content

Commit ccac1b0

Browse files
authored
add oauth verify api (#291)
1 parent ef00781 commit ccac1b0

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

docs/api-reference/oauth.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class OAuth {
1111

1212
issueAccessToken(client_id: string, client_secret: string): Promise<Types.ChannelAccessToken>
1313
revokeAccessToken(access_token: string): Promise<{}>
14+
verifyAccessToken(access_token: string): Promise<Types.VerifyAccessToken>
1415
issueChannelAccessTokenV2_1(
1516
client_assertion: string,
1617
): Promise<Types.ChannelAccessToken>
@@ -22,6 +23,12 @@ class OAuth {
2223
client_secret: string,
2324
access_token: string,
2425
): Promise<{}>
26+
verifyIdToken(
27+
id_token: string,
28+
client_id: string,
29+
nonce: string = undefined,
30+
user_id: string = undefined,
31+
): Promise<Types.VerifyIDToken>
2532
}
2633
```
2734

@@ -66,9 +73,19 @@ It corresponds to the [Issue channel access token](https://developers.line.biz/e
6673
const { access_token, expires_in, token_type } = await oauth.issueAccessToken("client_id", "client_secret");
6774
```
6875

76+
77+
#### `verifyAccessToken(access_token: string): Promise<Types.VerifyAccessToken>`
78+
79+
It corresponds to the [Verify access token validity](https://developers.line.biz/en/reference/line-login/#verify-access-token) API.
80+
81+
82+
``` js
83+
await oauth.verifyAccessToken("access_token");
84+
```
85+
6986
#### `revokeAccessToken(access_token: string): Promise<{}>`
7087

71-
It corresponds to the [Revoke channel access token](https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token) API.
88+
It corresponds to the [Revoke channel access token](https://developers.line.biz/en/reference/line-login/#revoke-access-token) API.
7289

7390

7491
``` js
@@ -86,3 +103,7 @@ It corresponds to the [Get all valid channel access token key IDs v2.1](https://
86103
#### revokeChannelAccessTokenV2_1(client_id: string, client_secret: string, access_token: string): Promise<{}>
87104

88105
It corresponds to the [Revoke channel access token v2.1](https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1) API.
106+
107+
#### verifyIdToken(id_token: string, client_id: string, nonce: string = undefined, user_id: string = undefined): Promise<{}>
108+
109+
It corresponds to the [Verify ID token v2.1](https://developers.line.biz/en/reference/line-login/#verify-id-token) API.

lib/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,26 @@ export class OAuth {
746746
return this.http.postForm(`${OAUTH_BASE_PREFIX}/revoke`, { access_token });
747747
}
748748

749+
public verifyAccessToken(
750+
access_token: string,
751+
): Promise<Types.VerifyAccessToken> {
752+
return this.http.get(`${OAUTH_BASE_PREFIX_V2_1}/verify`, { access_token });
753+
}
754+
755+
public verifyIdToken(
756+
id_token: string,
757+
client_id: string,
758+
nonce?: string,
759+
user_id?: string,
760+
): Promise<Types.VerifyIDToken> {
761+
return this.http.postForm(`${OAUTH_BASE_PREFIX}/verify`, {
762+
id_token,
763+
client_id,
764+
nonce,
765+
user_id,
766+
});
767+
}
768+
749769
public issueChannelAccessTokenV2_1(
750770
client_assertion: string,
751771
): Promise<Types.ChannelAccessToken> {

lib/types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,29 @@ export type ChannelAccessToken = {
26902690
key_id?: string;
26912691
};
26922692

2693+
export type VerifyAccessToken = {
2694+
scope: string;
2695+
client_id: string;
2696+
expires_in: number;
2697+
};
2698+
2699+
export type VerifyIDToken = {
2700+
scope: string;
2701+
client_id: string;
2702+
expires_in: number;
2703+
2704+
iss: string;
2705+
sub: string;
2706+
aud: number;
2707+
exp: number;
2708+
iat: number;
2709+
nonce: string;
2710+
amr: string[];
2711+
name: string;
2712+
picture: string;
2713+
email: string;
2714+
};
2715+
26932716
/**
26942717
* Response body of get group summary.
26952718
*

test/client.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,39 @@ describe("oauth", () => {
11011101
deepEqual(res, {});
11021102
});
11031103

1104+
it("verifyAccessToken", async () => {
1105+
const access_token = "test_channel_access_token";
1106+
const scope = nock(OAUTH_BASE_PREFIX_V2_1)
1107+
.get("/verify")
1108+
.query({
1109+
access_token,
1110+
})
1111+
.reply(200, {});
1112+
1113+
const res = await oauth.verifyAccessToken(access_token);
1114+
equal(scope.isDone(), true);
1115+
deepEqual(res, {});
1116+
});
1117+
1118+
it("verifyIdToken", async () => {
1119+
const id_token = "test_channel_access_token";
1120+
const client_id = "test_client_id";
1121+
const nonce = "test_nonce";
1122+
const user_id = "test_user_id";
1123+
const scope = nock(OAUTH_BASE_PREFIX, interceptionOption)
1124+
.post("/verify", {
1125+
id_token,
1126+
client_id,
1127+
nonce,
1128+
user_id,
1129+
})
1130+
.reply(200, {});
1131+
1132+
const res = await oauth.verifyIdToken(id_token, client_id, nonce, user_id);
1133+
equal(scope.isDone(), true);
1134+
deepEqual(res, {});
1135+
});
1136+
11041137
it("issueChannelAccessTokenV2_1", async () => {
11051138
const client_assertion = "client_assertion";
11061139
const reply = {

0 commit comments

Comments
 (0)