Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] LINE: implement issue, revoke access token #400

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/messaging-api-line/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"axios": "^0.18.0",
"axios-error": "^0.7.8",
"camelcase-keys": "^4.2.0",
"debug": "^4.0.1",
"image-type": "^3.0.0",
"invariant": "^2.2.4",
Expand Down
41 changes: 41 additions & 0 deletions packages/messaging-api-line/src/LineClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow */
import AxiosError from 'axios-error';
import axios from 'axios';
import camelcaseKeys from 'camelcase-keys';
import debug from 'debug';
import imageType from 'image-type';
import invariant from 'invariant';
Expand Down Expand Up @@ -73,6 +74,46 @@ export default class LineClient {
return new LineClient(accessTokenOrConfig, channelSecret);
}

static async issueAccessToken({
clientId,
clientSecret,
}: {
clientId: string,
clientSecret: string,
}): Promise<{ accessToken: string, expiresIn: number, tokenType: string }> {
return axios
.post(
'https://api.line.me/v2/oauth/accessToken',
{
grant_type: 'client_credentials',
client_id: clientId,
client_secret: clientSecret,
},
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}
)
.then(res => camelcaseKeys(res.data), handleError);
}

static async revokeAccessToken(accessToken: string): Promise<{}> {
return axios
.post(
'https://api.line.me/v2/oauth/revoke',
{
access_token: accessToken,
},
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
}
)
.then(res => camelcaseKeys(res.data), handleError);
}

_accessToken: string;

_channelSecret: string;
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ camelcase-keys@^2.0.0:
camelcase "^2.0.0"
map-obj "^1.0.0"

camelcase-keys@^4.0.0:
camelcase-keys@^4.0.0, camelcase-keys@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/camelcase-keys/-/camelcase-keys-4.2.0.tgz#a2aa5fb1af688758259c32c141426d78923b9b77"
dependencies:
Expand Down