line-node 0.0.3 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.cjs.js → index.cjs} +19 -46
- package/dist/{index.esm.js → index.es.js} +17 -44
- package/{types → dist/types}/helpers/randomString.d.ts +0 -0
- package/{types → dist/types}/index.d.ts +0 -0
- package/{types → dist/types}/lib/getLineLogin.d.ts +0 -0
- package/{types → dist/types}/lib/getParamsFromLoginCallback.d.ts +0 -0
- package/{types → dist/types}/lib/index.d.ts +0 -0
- package/{types → dist/types}/libNode/decodeIdToken.d.ts +0 -0
- package/{types → dist/types}/libNode/index.d.ts +0 -0
- package/{types → dist/types}/libNode/issueAccessToken.d.ts +0 -0
- package/package.json +65 -31
- package/.eslintignore +0 -9
- package/.eslintrc.js +0 -18
- package/.github/FUNDING.yml +0 -12
- package/.prettierrc +0 -9
- package/.vscode/settings.json +0 -47
- package/build.js +0 -57
- package/src/helpers/randomString.ts +0 -9
- package/src/index.ts +0 -2
- package/src/lib/getLineLogin.ts +0 -72
- package/src/lib/getParamsFromLoginCallback.ts +0 -49
- package/src/lib/index.ts +0 -2
- package/src/libNode/decodeIdToken.ts +0 -67
- package/src/libNode/index.ts +0 -2
- package/src/libNode/issueAccessToken.ts +0 -89
- package/tsconfig.json +0 -13
- package/types/types.d.ts +0 -0
|
@@ -31,7 +31,7 @@ function randomString(length = 20) {
|
|
|
31
31
|
function getLineLoginUrl(params) {
|
|
32
32
|
const { response_type = 'code', state = randomString(), scope = 'openid', redirect_uri: _redirect_uri, } = params;
|
|
33
33
|
const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F');
|
|
34
|
-
const paramsObject =
|
|
34
|
+
const paramsObject = { ...params, response_type, redirect_uri, state, scope };
|
|
35
35
|
const query = Object.entries(paramsObject)
|
|
36
36
|
.map((entry) => entry.join('='))
|
|
37
37
|
.join('&');
|
|
@@ -56,32 +56,7 @@ function getParamsFromLoginCallback(callbackUrlTriggered) {
|
|
|
56
56
|
return queryObject;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
Copyright (c) Microsoft Corporation.
|
|
61
|
-
|
|
62
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
63
|
-
purpose with or without fee is hereby granted.
|
|
64
|
-
|
|
65
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
66
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
67
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
68
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
69
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
70
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
71
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
72
|
-
***************************************************************************** */
|
|
73
|
-
|
|
74
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
75
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
76
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
77
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
78
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
79
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
80
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const post = got__default['default'].post;
|
|
59
|
+
const post = got__default["default"].post;
|
|
85
60
|
/**
|
|
86
61
|
* (Node only) Makes a POST request to retrieve an access token from LINE. This uses GOT as a dependency to make the request.
|
|
87
62
|
* Can throw errors.
|
|
@@ -91,28 +66,26 @@ const post = got__default['default'].post;
|
|
|
91
66
|
* @param {IssueAccessTokenParams} params
|
|
92
67
|
* @returns {Promise<IssueAccessTokenResponse>}
|
|
93
68
|
*/
|
|
94
|
-
function issueAccessToken(params) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
responseType: 'json',
|
|
109
|
-
});
|
|
110
|
-
const { body } = response;
|
|
111
|
-
return body;
|
|
69
|
+
async function issueAccessToken(params) {
|
|
70
|
+
const { grant_type = 'authorization_code', code, redirect_uri, client_id, client_secret } = params;
|
|
71
|
+
if (!code || !redirect_uri || !client_id || !client_secret) {
|
|
72
|
+
throw new Error('Missing information in params');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* To get an access token, make an HTTP POST request with the authorization code. Once you have an access token, you can use it to make API calls. The access token is issued at the following endpoint.
|
|
76
|
+
* The information in the request body should be:
|
|
77
|
+
* Content-Type: application/x-www-form-urlencoded
|
|
78
|
+
*/
|
|
79
|
+
const form = { grant_type, code, redirect_uri, client_id, client_secret };
|
|
80
|
+
const response = await post('https://api.line.me/oauth2/v2.1/token', {
|
|
81
|
+
form,
|
|
82
|
+
responseType: 'json',
|
|
112
83
|
});
|
|
84
|
+
const { body } = response;
|
|
85
|
+
return body;
|
|
113
86
|
}
|
|
114
87
|
|
|
115
|
-
const { decode } = jwt__default[
|
|
88
|
+
const { decode } = jwt__default["default"];
|
|
116
89
|
/**
|
|
117
90
|
* (Node only) Returns a decoded LINE id token. Uses the nodeJS 'jsonwebtoken' dependency.
|
|
118
91
|
* This id Token should be validated!
|
|
@@ -22,7 +22,7 @@ function randomString(length = 20) {
|
|
|
22
22
|
function getLineLoginUrl(params) {
|
|
23
23
|
const { response_type = 'code', state = randomString(), scope = 'openid', redirect_uri: _redirect_uri, } = params;
|
|
24
24
|
const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F');
|
|
25
|
-
const paramsObject =
|
|
25
|
+
const paramsObject = { ...params, response_type, redirect_uri, state, scope };
|
|
26
26
|
const query = Object.entries(paramsObject)
|
|
27
27
|
.map((entry) => entry.join('='))
|
|
28
28
|
.join('&');
|
|
@@ -47,31 +47,6 @@ function getParamsFromLoginCallback(callbackUrlTriggered) {
|
|
|
47
47
|
return queryObject;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/*! *****************************************************************************
|
|
51
|
-
Copyright (c) Microsoft Corporation.
|
|
52
|
-
|
|
53
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
54
|
-
purpose with or without fee is hereby granted.
|
|
55
|
-
|
|
56
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
57
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
58
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
59
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
60
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
61
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
62
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
63
|
-
***************************************************************************** */
|
|
64
|
-
|
|
65
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
66
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
67
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
68
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
69
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
70
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
71
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
50
|
const post = got.post;
|
|
76
51
|
/**
|
|
77
52
|
* (Node only) Makes a POST request to retrieve an access token from LINE. This uses GOT as a dependency to make the request.
|
|
@@ -82,25 +57,23 @@ const post = got.post;
|
|
|
82
57
|
* @param {IssueAccessTokenParams} params
|
|
83
58
|
* @returns {Promise<IssueAccessTokenResponse>}
|
|
84
59
|
*/
|
|
85
|
-
function issueAccessToken(params) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
responseType: 'json',
|
|
100
|
-
});
|
|
101
|
-
const { body } = response;
|
|
102
|
-
return body;
|
|
60
|
+
async function issueAccessToken(params) {
|
|
61
|
+
const { grant_type = 'authorization_code', code, redirect_uri, client_id, client_secret } = params;
|
|
62
|
+
if (!code || !redirect_uri || !client_id || !client_secret) {
|
|
63
|
+
throw new Error('Missing information in params');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* To get an access token, make an HTTP POST request with the authorization code. Once you have an access token, you can use it to make API calls. The access token is issued at the following endpoint.
|
|
67
|
+
* The information in the request body should be:
|
|
68
|
+
* Content-Type: application/x-www-form-urlencoded
|
|
69
|
+
*/
|
|
70
|
+
const form = { grant_type, code, redirect_uri, client_id, client_secret };
|
|
71
|
+
const response = await post('https://api.line.me/oauth2/v2.1/token', {
|
|
72
|
+
form,
|
|
73
|
+
responseType: 'json',
|
|
103
74
|
});
|
|
75
|
+
const { body } = response;
|
|
76
|
+
return body;
|
|
104
77
|
}
|
|
105
78
|
|
|
106
79
|
const { decode } = jwt;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,38 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "line-node",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "1.0.2",
|
|
5
6
|
"description": "LINE SDK for TypeScript",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
"module": "./dist/index.es.js",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.es.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"types": "./dist/types/index.d.ts"
|
|
15
|
+
}
|
|
14
16
|
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
15
20
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
21
|
+
"node": ">=12.13"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "echo na",
|
|
25
|
+
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
26
|
+
"build": "rollup -c ./scripts/build.js",
|
|
27
|
+
"release": "npm run lint && del dist && npm run build && np"
|
|
17
28
|
},
|
|
18
29
|
"dependencies": {
|
|
19
|
-
"got": "^11.8.
|
|
30
|
+
"got": "^11.8.3",
|
|
20
31
|
"jsonwebtoken": "^8.5.1"
|
|
21
32
|
},
|
|
22
33
|
"devDependencies": {
|
|
23
|
-
"@types/jsonwebtoken": "^8.5.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
25
|
-
"@typescript-eslint/parser": "^
|
|
26
|
-
"
|
|
27
|
-
"eslint": "^7.
|
|
28
|
-
"eslint-config-prettier": "^
|
|
29
|
-
"eslint-plugin-tree-shaking": "^1.
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"rollup
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
36
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
37
|
+
"del-cli": "^4.0.1",
|
|
38
|
+
"eslint": "^8.7.0",
|
|
39
|
+
"eslint-config-prettier": "^8.3.0",
|
|
40
|
+
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
41
|
+
"np": "^7.6.0",
|
|
42
|
+
"prettier": "^2.5.1",
|
|
43
|
+
"rollup": "^2.66.1",
|
|
44
|
+
"rollup-plugin-typescript2": "^0.31.1",
|
|
45
|
+
"typescript": "^4.5.5",
|
|
46
|
+
"vitest": "^0.2.3"
|
|
36
47
|
},
|
|
37
48
|
"keywords": [
|
|
38
49
|
"line",
|
|
@@ -41,6 +52,7 @@
|
|
|
41
52
|
"line-sdk"
|
|
42
53
|
],
|
|
43
54
|
"author": "Luca Ban - Mesqueeb",
|
|
55
|
+
"funding": "https://github.com/sponsors/mesqueeb",
|
|
44
56
|
"license": "MIT",
|
|
45
57
|
"bugs": {
|
|
46
58
|
"url": "https://github.com/mesqueeb/line-node/issues"
|
|
@@ -50,13 +62,35 @@
|
|
|
50
62
|
"type": "git",
|
|
51
63
|
"url": "git+https://github.com/mesqueeb/line-node.git"
|
|
52
64
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
65
|
+
"np": {
|
|
66
|
+
"yarn": false,
|
|
67
|
+
"branch": "production"
|
|
68
|
+
},
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"ignorePatterns": [
|
|
71
|
+
"node_modules",
|
|
72
|
+
"dist",
|
|
73
|
+
"scripts",
|
|
74
|
+
"test"
|
|
75
|
+
],
|
|
76
|
+
"root": true,
|
|
77
|
+
"parser": "@typescript-eslint/parser",
|
|
78
|
+
"plugins": [
|
|
79
|
+
"@typescript-eslint",
|
|
80
|
+
"tree-shaking"
|
|
81
|
+
],
|
|
82
|
+
"extends": [
|
|
83
|
+
"eslint:recommended",
|
|
84
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
85
|
+
"plugin:@typescript-eslint/recommended",
|
|
86
|
+
"prettier"
|
|
56
87
|
],
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
88
|
+
"rules": {
|
|
89
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
90
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
91
|
+
"@typescript-eslint/ban-ts-ignore": "off",
|
|
92
|
+
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
93
|
+
"@typescript-eslint/ban-ts-comment": "off"
|
|
94
|
+
}
|
|
61
95
|
}
|
|
62
96
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
|
|
2
|
-
module.exports = {
|
|
3
|
-
root: true,
|
|
4
|
-
parser: '@typescript-eslint/parser',
|
|
5
|
-
plugins: ['@typescript-eslint', 'tree-shaking'],
|
|
6
|
-
extends: [
|
|
7
|
-
'eslint:recommended',
|
|
8
|
-
'plugin:@typescript-eslint/eslint-recommended',
|
|
9
|
-
'plugin:@typescript-eslint/recommended',
|
|
10
|
-
'prettier/@typescript-eslint',
|
|
11
|
-
],
|
|
12
|
-
rules: {
|
|
13
|
-
'@typescript-eslint/no-explicit-any': 'off',
|
|
14
|
-
'@typescript-eslint/ban-ts-ignore': 'off',
|
|
15
|
-
'tree-shaking/no-side-effects-in-initialization': 'error',
|
|
16
|
-
'@typescript-eslint/camelcase': 'off'
|
|
17
|
-
},
|
|
18
|
-
}
|
package/.github/FUNDING.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# These are supported funding model platforms
|
|
2
|
-
|
|
3
|
-
github: mesqueeb
|
|
4
|
-
patreon: # Replace with a single Patreon username
|
|
5
|
-
open_collective: # Replace with a single Open Collective username
|
|
6
|
-
ko_fi: # Replace with a single Ko-fi username
|
|
7
|
-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
|
8
|
-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
|
9
|
-
liberapay: # Replace with a single Liberapay username
|
|
10
|
-
issuehunt: # Replace with a single IssueHunt username
|
|
11
|
-
otechie: # Replace with a single Otechie username
|
|
12
|
-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
package/.prettierrc
DELETED
package/.vscode/settings.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"editor.formatOnSave": true,
|
|
3
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
4
|
-
"[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
|
|
5
|
-
"[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
|
|
6
|
-
"[vue]": {
|
|
7
|
-
// octref.vetur is to be enabled after this is released:
|
|
8
|
-
// https://github.com/vuejs/vetur/issues/1925
|
|
9
|
-
// "editor.defaultFormatter": "octref.vetur"
|
|
10
|
-
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
11
|
-
},
|
|
12
|
-
"[sass]": { "editor.defaultFormatter": "syler.sass-indented" },
|
|
13
|
-
// make sure vetur is enabled
|
|
14
|
-
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"],
|
|
15
|
-
"vetur.experimental.templateInterpolationService": true,
|
|
16
|
-
"vetur.format.enable": true,
|
|
17
|
-
"vetur.validation.style": true,
|
|
18
|
-
"vetur.validation.template": true,
|
|
19
|
-
"vetur.validation.script": true,
|
|
20
|
-
// disable conflicting formatting
|
|
21
|
-
"javascript.validate.enable": true,
|
|
22
|
-
"typescript.format.enable": true,
|
|
23
|
-
"standard.enable": false,
|
|
24
|
-
// global important defaults
|
|
25
|
-
"editor.tabSize": 2, // make sure this is the same as .prettierrc
|
|
26
|
-
"editor.insertSpaces": true,
|
|
27
|
-
"files.trimFinalNewlines": true,
|
|
28
|
-
"files.trimTrailingWhitespace": true,
|
|
29
|
-
// script
|
|
30
|
-
"vetur.format.defaultFormatter.ts": "prettier",
|
|
31
|
-
"vetur.format.defaultFormatter.js": "prettier",
|
|
32
|
-
// stylus
|
|
33
|
-
"vetur.format.defaultFormatter.stylus": "stylus-supremacy",
|
|
34
|
-
"stylusSupremacy.insertColons": true,
|
|
35
|
-
"stylusSupremacy.insertBraces": false,
|
|
36
|
-
"stylusSupremacy.insertSemicolons": false,
|
|
37
|
-
"languageStylus.useSeparator": true,
|
|
38
|
-
// sass
|
|
39
|
-
"vetur.format.defaultFormatter.sass": "sass-formatter",
|
|
40
|
-
"sass.format.debug": false,
|
|
41
|
-
"sass.format.deleteEmptyRows": true,
|
|
42
|
-
"sass.format.deleteWhitespace": true,
|
|
43
|
-
"sass.format.convert": true,
|
|
44
|
-
"sass.format.setPropertySpace": true,
|
|
45
|
-
// typescript
|
|
46
|
-
"typescript.tsdk": "node_modules/typescript/lib"
|
|
47
|
-
}
|
package/build.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
// npm install rollup-plugin-typescript2 typescript --save-dev
|
|
4
|
-
import typescript from 'rollup-plugin-typescript2'
|
|
5
|
-
|
|
6
|
-
// ------------------------------------------------------------------------------------------
|
|
7
|
-
// formats
|
|
8
|
-
// ------------------------------------------------------------------------------------------
|
|
9
|
-
// amd – Asynchronous Module Definition, used with module loaders like RequireJS
|
|
10
|
-
// cjs – CommonJS, suitable for Node and Browserify/Webpack
|
|
11
|
-
// esm – Keep the bundle as an ES module file
|
|
12
|
-
// iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
|
|
13
|
-
// umd – Universal Module Definition, works as amd, cjs and iife all in one
|
|
14
|
-
// system – Native format of the SystemJS loader
|
|
15
|
-
|
|
16
|
-
// ------------------------------------------------------------------------------------------
|
|
17
|
-
// setup
|
|
18
|
-
// ------------------------------------------------------------------------------------------
|
|
19
|
-
const pkg = require('./package.json')
|
|
20
|
-
const name = pkg.name
|
|
21
|
-
const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
|
|
22
|
-
const external = Object.keys(pkg.dependencies || [])
|
|
23
|
-
const plugins = [
|
|
24
|
-
typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
// ------------------------------------------------------------------------------------------
|
|
28
|
-
// Builds
|
|
29
|
-
// ------------------------------------------------------------------------------------------
|
|
30
|
-
function defaults (config) {
|
|
31
|
-
// defaults
|
|
32
|
-
const defaults = {
|
|
33
|
-
plugins,
|
|
34
|
-
external,
|
|
35
|
-
}
|
|
36
|
-
// defaults.output
|
|
37
|
-
config.output = config.output.map(output => {
|
|
38
|
-
return Object.assign(
|
|
39
|
-
{
|
|
40
|
-
sourcemap: false,
|
|
41
|
-
name: className,
|
|
42
|
-
},
|
|
43
|
-
output
|
|
44
|
-
)
|
|
45
|
-
})
|
|
46
|
-
return Object.assign(defaults, config)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default [
|
|
50
|
-
defaults({
|
|
51
|
-
input: 'src/index.ts',
|
|
52
|
-
output: [
|
|
53
|
-
{ file: 'dist/index.cjs.js', format: 'cjs' },
|
|
54
|
-
{ file: 'dist/index.esm.js', format: 'esm' },
|
|
55
|
-
],
|
|
56
|
-
}),
|
|
57
|
-
]
|
package/src/index.ts
DELETED
package/src/lib/getLineLogin.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { randomString } from '../helpers/randomString'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
5
|
-
*/
|
|
6
|
-
export type LineLoginUrlParams = {
|
|
7
|
-
/**
|
|
8
|
-
* (Optional - default 'code') code. This tells the LINE Platform to return an authorization code.
|
|
9
|
-
*/
|
|
10
|
-
response_type?: string
|
|
11
|
-
/**
|
|
12
|
-
* (Required) Channel ID. Unique identifier for your channel issued by LINE.
|
|
13
|
-
*/
|
|
14
|
-
client_id: string
|
|
15
|
-
/**
|
|
16
|
-
* (Required) Callback URL. URL that users are redirected to after authentication and authorization. Must match one of the the callback URLs registered for your channel in the console.
|
|
17
|
-
*/
|
|
18
|
-
redirect_uri: string
|
|
19
|
-
/**
|
|
20
|
-
* (Optional - default to a random string) A unique alphanumeric string used to prevent cross-site request forgery. This value should be randomly generated by your application. Cannot be a URL-encoded string.
|
|
21
|
-
*/
|
|
22
|
-
state?: string
|
|
23
|
-
/**
|
|
24
|
-
* (Optional - default 'openid') Permissions requested to the user. For more information, see scopes.
|
|
25
|
-
* To obtain the email address of a user, you must first apply for permission.
|
|
26
|
-
* An access token with the profile scope is required to get the friendship status between a user and a LINE Official Account.
|
|
27
|
-
*/
|
|
28
|
-
scope?: 'profile' | 'profile%20openid' | 'profile%20openid%20email' | 'openid' | 'openid%20email'
|
|
29
|
-
/**
|
|
30
|
-
* (Optional) A string used to prevent replay attacks. This value is returned in an ID token.
|
|
31
|
-
*/
|
|
32
|
-
nonce?: string
|
|
33
|
-
/**
|
|
34
|
-
* (Optional) consent. Used to force the consent screen to be displayed even if the user has already granted all requested permissions.
|
|
35
|
-
*/
|
|
36
|
-
prompt?: string
|
|
37
|
-
/**
|
|
38
|
-
* (Optional) The allowable elapsed time in seconds since the last time the user was authenticated. Corresponds to the max_age parameter defined in the "Authentication Request" section of OpenID Connect Core 1.0.
|
|
39
|
-
*/
|
|
40
|
-
max_age?: number
|
|
41
|
-
/**
|
|
42
|
-
* (Optional) Display language for LINE Login screens. Specify as one or more RFC 5646 (BCP 47) language tags, separated by spaces, in order of preference. Corresponds to the ui_locales parameter defined in the "Authentication Request" section of OpenID Connect Core 1.0.
|
|
43
|
-
*/
|
|
44
|
-
ui_locales?: string
|
|
45
|
-
/**
|
|
46
|
-
* (Optional) Displays an option to add a LINE Official Account as a friend during login. Set to either normal or aggressive. For more information, see Add a LINE Official Account as a friend when logged in (bot link).
|
|
47
|
-
*/
|
|
48
|
-
bot_prompt?: string
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get a URL that users can access to login with LINE and be redirected to your app again.
|
|
53
|
-
*
|
|
54
|
-
* LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
55
|
-
*
|
|
56
|
-
* @param {LineLoginUrlParams} params Only client_id & redirect_uri are required props.
|
|
57
|
-
* @returns {string} the `https://access.line.me/oauth2/v2.1/authorize${query}` URL with correct query
|
|
58
|
-
*/
|
|
59
|
-
export function getLineLoginUrl(params: LineLoginUrlParams): string {
|
|
60
|
-
const {
|
|
61
|
-
response_type = 'code',
|
|
62
|
-
state = randomString(),
|
|
63
|
-
scope = 'openid',
|
|
64
|
-
redirect_uri: _redirect_uri,
|
|
65
|
-
} = params
|
|
66
|
-
const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F')
|
|
67
|
-
const paramsObject = { ...params, response_type, redirect_uri, state, scope }
|
|
68
|
-
const query = Object.entries(paramsObject)
|
|
69
|
-
.map((entry) => entry.join('='))
|
|
70
|
-
.join('&')
|
|
71
|
-
return `https://access.line.me/oauth2/v2.1/authorize?${query}`
|
|
72
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export type LoginCallbackParamsSuccess = {
|
|
2
|
-
/**
|
|
3
|
-
* Authorization code used to get an access token. Valid for 10 minutes. This authorization code can only be used once.
|
|
4
|
-
*/
|
|
5
|
-
code: string
|
|
6
|
-
/**
|
|
7
|
-
* state parameter included in the authorization URL of original request. Your application should verify that this value matches the one in the original request.
|
|
8
|
-
*/
|
|
9
|
-
state: string
|
|
10
|
-
/**
|
|
11
|
-
* true if the friendship status between the user and the LINE Official Account changes during login. Otherwise, the value is false. This parameter is only returned if the bot_prompt query parameter is specified when making an authorization request and the option to add your LINE Official Account as a friend when the user logged in is displayed. For more information, see Add a LINE Official Account as a friend when logged in (bot link).
|
|
12
|
-
*/
|
|
13
|
-
friendship_status_changed?: boolean
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type LoginCallbackParamsError = {
|
|
17
|
-
/**
|
|
18
|
-
* (Optional) Error code.
|
|
19
|
-
*/
|
|
20
|
-
error: 'access_denied' | string
|
|
21
|
-
/**
|
|
22
|
-
* (Optional) Details of the error.
|
|
23
|
-
*/
|
|
24
|
-
error_description?: string
|
|
25
|
-
/**
|
|
26
|
-
* (Optional) OAuth 2.0 state value. Required if the authorization Request included the state parameter.
|
|
27
|
-
*/
|
|
28
|
-
state?: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Once the user is authenticated and authorization is complete, the HTTP status code 302 and query parameters are returned in the callback URL. This function converts the callback URL to an object with the query parameters.
|
|
33
|
-
*
|
|
34
|
-
* @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
35
|
-
* @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
|
|
36
|
-
* @example // Success example:
|
|
37
|
-
HTTP/1.1 302 Found
|
|
38
|
-
Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
39
|
-
* @example // Error example:
|
|
40
|
-
Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
|
|
41
|
-
*/
|
|
42
|
-
export function getParamsFromLoginCallback(
|
|
43
|
-
callbackUrlTriggered: string,
|
|
44
|
-
): LoginCallbackParamsSuccess | LoginCallbackParamsError {
|
|
45
|
-
const query = callbackUrlTriggered.split('?')[1]
|
|
46
|
-
const queryEntries = query.split('&').map((q) => q.split('='))
|
|
47
|
-
const queryObject = Object.fromEntries(queryEntries)
|
|
48
|
-
return queryObject
|
|
49
|
-
}
|
package/src/lib/index.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import jwt from 'jsonwebtoken'
|
|
2
|
-
const { decode } = jwt
|
|
3
|
-
|
|
4
|
-
export type DecodedIdToken = {
|
|
5
|
-
header: { typ: 'JWT'; alg: 'HS256' }
|
|
6
|
-
payload: {
|
|
7
|
-
/**
|
|
8
|
-
* https://access.line.me. URL where the ID token is generated.
|
|
9
|
-
*/
|
|
10
|
-
iss: 'https://access.line.me' | string
|
|
11
|
-
/**
|
|
12
|
-
* User ID for which the ID token is generated
|
|
13
|
-
*/
|
|
14
|
-
sub: string
|
|
15
|
-
/**
|
|
16
|
-
* Channel ID
|
|
17
|
-
*/
|
|
18
|
-
aud: string
|
|
19
|
-
/**
|
|
20
|
-
* The expiry date of the token in UNIX time.
|
|
21
|
-
*/
|
|
22
|
-
exp: number
|
|
23
|
-
/**
|
|
24
|
-
* Time when the ID token was generated in UNIX time.
|
|
25
|
-
*/
|
|
26
|
-
iat: number
|
|
27
|
-
/**
|
|
28
|
-
* (Optional) Time when the user was authenticated in UNIX time. Not included if the max_age parameter wasn't specified in the authorization request.
|
|
29
|
-
*/
|
|
30
|
-
auth_time?: number
|
|
31
|
-
/**
|
|
32
|
-
* (Optional) The nonce value specified in the authorization URL. Not included if the nonce value was not specified in the authorization request.
|
|
33
|
-
*/
|
|
34
|
-
nonce?: string
|
|
35
|
-
/**
|
|
36
|
-
* List of authentication methods used by the user. For each authentication method, see Authentication process. One of:
|
|
37
|
-
* pwd: Log in with email and password
|
|
38
|
-
* lineautologin: LINE automatic login (including through LINE SDK)
|
|
39
|
-
* lineqr: Log in with QR code
|
|
40
|
-
* linesso: Log in with single sign-on
|
|
41
|
-
*/
|
|
42
|
-
amr: ('pwd' | 'lineautologin' | 'lineqr' | 'linesso' | 'name')[]
|
|
43
|
-
/**
|
|
44
|
-
* User's display name. Not included if the profile scope was not specified in the authorization request.
|
|
45
|
-
*/
|
|
46
|
-
name: string
|
|
47
|
-
/**
|
|
48
|
-
* (Optional) User's profile image URL. Not included if the profile scope was not specified in the authorization request.
|
|
49
|
-
*/
|
|
50
|
-
picture?: string
|
|
51
|
-
/**
|
|
52
|
-
* (Optional) User's email address. Not included if the email scope was not specified in the authorization request.
|
|
53
|
-
*/
|
|
54
|
-
email?: string
|
|
55
|
-
}
|
|
56
|
-
signature: string
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* (Node only) Returns a decoded LINE id token. Uses the nodeJS 'jsonwebtoken' dependency.
|
|
61
|
-
* This id Token should be validated!
|
|
62
|
-
* LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#decode-and-validate-id-token
|
|
63
|
-
*/
|
|
64
|
-
export function decodeIdToken(idToken: string): DecodedIdToken {
|
|
65
|
-
// get the decoded payload ignoring signature, no secretOrPrivateKey needed
|
|
66
|
-
return decode(idToken, { complete: true }) as DecodedIdToken
|
|
67
|
-
}
|
package/src/libNode/index.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import got from 'got'
|
|
2
|
-
const post = got.post
|
|
3
|
-
|
|
4
|
-
export type IssueAccessTokenParams = {
|
|
5
|
-
/**
|
|
6
|
-
* (Optional - default: 'authorization_code') authorization_code. Specifies the grant type.
|
|
7
|
-
*/
|
|
8
|
-
grant_type?: string
|
|
9
|
-
/**
|
|
10
|
-
* (Required) Authorization code. Code returned in the authorization request.
|
|
11
|
-
*/
|
|
12
|
-
code: string
|
|
13
|
-
/**
|
|
14
|
-
* (Required) Callback URL. Must match one of the the callback URLs registered for your channel in the console.
|
|
15
|
-
*/
|
|
16
|
-
redirect_uri: string
|
|
17
|
-
/**
|
|
18
|
-
* (Required) Channel ID. Found in the console.
|
|
19
|
-
*/
|
|
20
|
-
client_id: string
|
|
21
|
-
/**
|
|
22
|
-
* (Required) Channel secret. Found in the console.
|
|
23
|
-
*/
|
|
24
|
-
client_secret: string
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The LINE Platform validates the request and returns an access token and other data as shown in the table below.
|
|
29
|
-
*
|
|
30
|
-
* New or changed LINE Login functions may cause changes in the structure of the payload JSON object. These changes may include added properties, variations in property order, and added/removed white space and line breaks. Design your backend so that it can handle payload data objects with unexpected structures.
|
|
31
|
-
*
|
|
32
|
-
* Returns status code 200 and a JSON object with the following information.
|
|
33
|
-
*/
|
|
34
|
-
export type IssueAccessTokenResponse = {
|
|
35
|
-
/**
|
|
36
|
-
* Access token. Valid for 30 days.
|
|
37
|
-
*/
|
|
38
|
-
access_token: string
|
|
39
|
-
/**
|
|
40
|
-
* Amount of time in seconds until the access token expires.
|
|
41
|
-
*/
|
|
42
|
-
expires_in: number
|
|
43
|
-
/**
|
|
44
|
-
* JSON Web Token (JWT) that includes information about the user. This field is returned only if openid is specified in the scope. For more information, see Verify ID token.
|
|
45
|
-
*/
|
|
46
|
-
id_token: string
|
|
47
|
-
/**
|
|
48
|
-
* Token used to get a new access token. Valid up until 90 days after the access token issued.
|
|
49
|
-
*/
|
|
50
|
-
refresh_token: string
|
|
51
|
-
/**
|
|
52
|
-
* Permissions granted by the user. However, the email scope is not returned as a value of the scope property even if the permission has been granted.
|
|
53
|
-
*/
|
|
54
|
-
scope: string
|
|
55
|
-
/**
|
|
56
|
-
* Bearer
|
|
57
|
-
*/
|
|
58
|
-
token_type: string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* (Node only) Makes a POST request to retrieve an access token from LINE. This uses GOT as a dependency to make the request.
|
|
63
|
-
* Can throw errors.
|
|
64
|
-
*
|
|
65
|
-
* LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#get-access-token
|
|
66
|
-
*
|
|
67
|
-
* @param {IssueAccessTokenParams} params
|
|
68
|
-
* @returns {Promise<IssueAccessTokenResponse>}
|
|
69
|
-
*/
|
|
70
|
-
export async function issueAccessToken(
|
|
71
|
-
params: IssueAccessTokenParams,
|
|
72
|
-
): Promise<IssueAccessTokenResponse> {
|
|
73
|
-
const { grant_type = 'authorization_code', code, redirect_uri, client_id, client_secret } = params
|
|
74
|
-
if (!code || !redirect_uri || !client_id || !client_secret) {
|
|
75
|
-
throw new Error('Missing information in params')
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* To get an access token, make an HTTP POST request with the authorization code. Once you have an access token, you can use it to make API calls. The access token is issued at the following endpoint.
|
|
79
|
-
* The information in the request body should be:
|
|
80
|
-
* Content-Type: application/x-www-form-urlencoded
|
|
81
|
-
*/
|
|
82
|
-
const form = { grant_type, code, redirect_uri, client_id, client_secret }
|
|
83
|
-
const response = await post<IssueAccessTokenResponse>('https://api.line.me/oauth2/v2.1/token', {
|
|
84
|
-
form,
|
|
85
|
-
responseType: 'json',
|
|
86
|
-
})
|
|
87
|
-
const { body } = response
|
|
88
|
-
return body
|
|
89
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"outDir": "./dist",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationDir": "./types/",
|
|
8
|
-
"target": "ES2015",
|
|
9
|
-
"lib": ["ES2015", "ES2016", "ES2017", "ES2018", "ES2019", "ES2020"],
|
|
10
|
-
"moduleResolution": "node"
|
|
11
|
-
},
|
|
12
|
-
"include": ["src/**/*", "test/**/*"]
|
|
13
|
-
}
|
package/types/types.d.ts
DELETED
|
File without changes
|