line-ts 1.0.4 → 2.0.1
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/helpers/randomString.d.ts +4 -0
- package/dist/helpers/randomString.js +9 -0
- package/dist/index.d.ts +2 -99
- package/dist/index.js +2 -25
- package/dist/{cjs/index.d.cts → lib/getLineLogin.d.ts} +2 -45
- package/dist/lib/getLineLogin.js +18 -0
- package/dist/lib/getParamsFromLoginCallback.d.ts +40 -0
- package/dist/lib/getParamsFromLoginCallback.js +17 -0
- package/package.json +20 -73
- package/dist/cjs/index.cjs +0 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,99 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
type LineLoginUrlParams = {
|
|
5
|
-
/**
|
|
6
|
-
* (Optional - default 'code') code. This tells the LINE Platform to return an authorization code.
|
|
7
|
-
*/
|
|
8
|
-
response_type?: string;
|
|
9
|
-
/**
|
|
10
|
-
* (Required) Channel ID. Unique identifier for your channel issued by LINE.
|
|
11
|
-
*/
|
|
12
|
-
client_id: string;
|
|
13
|
-
/**
|
|
14
|
-
* (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.
|
|
15
|
-
*/
|
|
16
|
-
redirect_uri: string;
|
|
17
|
-
/**
|
|
18
|
-
* (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.
|
|
19
|
-
*/
|
|
20
|
-
state?: string;
|
|
21
|
-
/**
|
|
22
|
-
* (Optional - default 'openid') Permissions requested to the user. For more information, see scopes.
|
|
23
|
-
* To obtain the email address of a user, you must first apply for permission.
|
|
24
|
-
* An access token with the profile scope is required to get the friendship status between a user and a LINE Official Account.
|
|
25
|
-
*/
|
|
26
|
-
scope?: 'profile' | 'profile%20openid' | 'profile%20openid%20email' | 'openid' | 'openid%20email';
|
|
27
|
-
/**
|
|
28
|
-
* (Optional) A string used to prevent replay attacks. This value is returned in an ID token.
|
|
29
|
-
*/
|
|
30
|
-
nonce?: string;
|
|
31
|
-
/**
|
|
32
|
-
* (Optional) consent. Used to force the consent screen to be displayed even if the user has already granted all requested permissions.
|
|
33
|
-
*/
|
|
34
|
-
prompt?: string;
|
|
35
|
-
/**
|
|
36
|
-
* (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.
|
|
37
|
-
*/
|
|
38
|
-
max_age?: number;
|
|
39
|
-
/**
|
|
40
|
-
* (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.
|
|
41
|
-
*/
|
|
42
|
-
ui_locales?: string;
|
|
43
|
-
/**
|
|
44
|
-
* (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).
|
|
45
|
-
*/
|
|
46
|
-
bot_prompt?: string;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Get a URL that users can access to login with LINE and be redirected to your app again.
|
|
50
|
-
*
|
|
51
|
-
* LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
52
|
-
*
|
|
53
|
-
* @param {LineLoginUrlParams} params Only client_id & redirect_uri are required props.
|
|
54
|
-
* @returns {string} the `https://access.line.me/oauth2/v2.1/authorize${query}` URL with correct query
|
|
55
|
-
*/
|
|
56
|
-
declare function getLineLoginUrl(params: LineLoginUrlParams): string;
|
|
57
|
-
|
|
58
|
-
type LoginCallbackParamsSuccess = {
|
|
59
|
-
/**
|
|
60
|
-
* Authorization code used to get an access token. Valid for 10 minutes. This authorization code can only be used once.
|
|
61
|
-
*/
|
|
62
|
-
code: string;
|
|
63
|
-
/**
|
|
64
|
-
* state parameter included in the authorization URL of original request. Your application should verify that this value matches the one in the original request.
|
|
65
|
-
*/
|
|
66
|
-
state: string;
|
|
67
|
-
/**
|
|
68
|
-
* 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).
|
|
69
|
-
*/
|
|
70
|
-
friendship_status_changed?: boolean;
|
|
71
|
-
};
|
|
72
|
-
type LoginCallbackParamsError = {
|
|
73
|
-
/**
|
|
74
|
-
* (Optional) Error code.
|
|
75
|
-
*/
|
|
76
|
-
error: 'access_denied' | string;
|
|
77
|
-
/**
|
|
78
|
-
* (Optional) Details of the error.
|
|
79
|
-
*/
|
|
80
|
-
error_description?: string;
|
|
81
|
-
/**
|
|
82
|
-
* (Optional) OAuth 2.0 state value. Required if the authorization Request included the state parameter.
|
|
83
|
-
*/
|
|
84
|
-
state?: string;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* 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.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
90
|
-
* @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
|
|
91
|
-
* @example // Success example:
|
|
92
|
-
HTTP/1.1 302 Found
|
|
93
|
-
Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
94
|
-
* @example // Error example:
|
|
95
|
-
Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
|
|
96
|
-
*/
|
|
97
|
-
declare function getParamsFromLoginCallback(callbackUrlTriggered: string): LoginCallbackParamsSuccess | LoginCallbackParamsError;
|
|
98
|
-
|
|
99
|
-
export { LineLoginUrlParams, LoginCallbackParamsError, LoginCallbackParamsSuccess, getLineLoginUrl, getParamsFromLoginCallback };
|
|
1
|
+
export * from './lib/getLineLogin.js';
|
|
2
|
+
export * from './lib/getParamsFromLoginCallback.js';
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function getLineLoginUrl(params) {
|
|
6
|
-
const {
|
|
7
|
-
response_type = "code",
|
|
8
|
-
state = randomString(),
|
|
9
|
-
scope = "openid",
|
|
10
|
-
redirect_uri: _redirect_uri
|
|
11
|
-
} = params;
|
|
12
|
-
const redirect_uri = _redirect_uri.replace(/:/g, "%3A").replace(/\//g, "%2F");
|
|
13
|
-
const paramsObject = { ...params, response_type, redirect_uri, state, scope };
|
|
14
|
-
const query = Object.entries(paramsObject).map((entry) => entry.join("=")).join("&");
|
|
15
|
-
return `https://access.line.me/oauth2/v2.1/authorize?${query}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getParamsFromLoginCallback(callbackUrlTriggered) {
|
|
19
|
-
const query = callbackUrlTriggered.split("?")[1];
|
|
20
|
-
const queryEntries = query.split("&").map((q) => q.split("="));
|
|
21
|
-
const queryObject = Object.fromEntries(queryEntries);
|
|
22
|
-
return queryObject;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { getLineLoginUrl, getParamsFromLoginCallback };
|
|
1
|
+
export * from './lib/getLineLogin.js';
|
|
2
|
+
export * from './lib/getParamsFromLoginCallback.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
3
3
|
*/
|
|
4
|
-
type LineLoginUrlParams = {
|
|
4
|
+
export type LineLoginUrlParams = {
|
|
5
5
|
/**
|
|
6
6
|
* (Optional - default 'code') code. This tells the LINE Platform to return an authorization code.
|
|
7
7
|
*/
|
|
@@ -53,47 +53,4 @@ type LineLoginUrlParams = {
|
|
|
53
53
|
* @param {LineLoginUrlParams} params Only client_id & redirect_uri are required props.
|
|
54
54
|
* @returns {string} the `https://access.line.me/oauth2/v2.1/authorize${query}` URL with correct query
|
|
55
55
|
*/
|
|
56
|
-
declare function getLineLoginUrl(params: LineLoginUrlParams): string;
|
|
57
|
-
|
|
58
|
-
type LoginCallbackParamsSuccess = {
|
|
59
|
-
/**
|
|
60
|
-
* Authorization code used to get an access token. Valid for 10 minutes. This authorization code can only be used once.
|
|
61
|
-
*/
|
|
62
|
-
code: string;
|
|
63
|
-
/**
|
|
64
|
-
* state parameter included in the authorization URL of original request. Your application should verify that this value matches the one in the original request.
|
|
65
|
-
*/
|
|
66
|
-
state: string;
|
|
67
|
-
/**
|
|
68
|
-
* 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).
|
|
69
|
-
*/
|
|
70
|
-
friendship_status_changed?: boolean;
|
|
71
|
-
};
|
|
72
|
-
type LoginCallbackParamsError = {
|
|
73
|
-
/**
|
|
74
|
-
* (Optional) Error code.
|
|
75
|
-
*/
|
|
76
|
-
error: 'access_denied' | string;
|
|
77
|
-
/**
|
|
78
|
-
* (Optional) Details of the error.
|
|
79
|
-
*/
|
|
80
|
-
error_description?: string;
|
|
81
|
-
/**
|
|
82
|
-
* (Optional) OAuth 2.0 state value. Required if the authorization Request included the state parameter.
|
|
83
|
-
*/
|
|
84
|
-
state?: string;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* 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.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
90
|
-
* @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
|
|
91
|
-
* @example // Success example:
|
|
92
|
-
HTTP/1.1 302 Found
|
|
93
|
-
Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
94
|
-
* @example // Error example:
|
|
95
|
-
Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
|
|
96
|
-
*/
|
|
97
|
-
declare function getParamsFromLoginCallback(callbackUrlTriggered: string): LoginCallbackParamsSuccess | LoginCallbackParamsError;
|
|
98
|
-
|
|
99
|
-
export { LineLoginUrlParams, LoginCallbackParamsError, LoginCallbackParamsSuccess, getLineLoginUrl, getParamsFromLoginCallback };
|
|
56
|
+
export declare function getLineLoginUrl(params: LineLoginUrlParams): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { randomString } from '../helpers/randomString.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get a URL that users can access to login with LINE and be redirected to your app again.
|
|
4
|
+
*
|
|
5
|
+
* LINE documentation: https://developers.line.biz/en/docs/line-login/integrate-line-login/#making-an-authorization-request
|
|
6
|
+
*
|
|
7
|
+
* @param {LineLoginUrlParams} params Only client_id & redirect_uri are required props.
|
|
8
|
+
* @returns {string} the `https://access.line.me/oauth2/v2.1/authorize${query}` URL with correct query
|
|
9
|
+
*/
|
|
10
|
+
export function getLineLoginUrl(params) {
|
|
11
|
+
const { response_type = 'code', state = randomString(), scope = 'openid', redirect_uri: _redirect_uri, } = params;
|
|
12
|
+
const redirect_uri = _redirect_uri.replace(/:/g, '%3A').replace(/\//g, '%2F');
|
|
13
|
+
const paramsObject = { ...params, response_type, redirect_uri, state, scope };
|
|
14
|
+
const query = Object.entries(paramsObject)
|
|
15
|
+
.map((entry) => entry.join('='))
|
|
16
|
+
.join('&');
|
|
17
|
+
return `https://access.line.me/oauth2/v2.1/authorize?${query}`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
export type LoginCallbackParamsError = {
|
|
16
|
+
/**
|
|
17
|
+
* (Optional) Error code.
|
|
18
|
+
*/
|
|
19
|
+
error: 'access_denied' | string;
|
|
20
|
+
/**
|
|
21
|
+
* (Optional) Details of the error.
|
|
22
|
+
*/
|
|
23
|
+
error_description?: string;
|
|
24
|
+
/**
|
|
25
|
+
* (Optional) OAuth 2.0 state value. Required if the authorization Request included the state parameter.
|
|
26
|
+
*/
|
|
27
|
+
state?: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* 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.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
33
|
+
* @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
|
|
34
|
+
* @example // Success example:
|
|
35
|
+
HTTP/1.1 302 Found
|
|
36
|
+
Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
37
|
+
* @example // Error example:
|
|
38
|
+
Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
|
|
39
|
+
*/
|
|
40
|
+
export declare function getParamsFromLoginCallback(callbackUrlTriggered: string): LoginCallbackParamsSuccess | LoginCallbackParamsError;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} callbackUrlTriggered eg. https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
5
|
+
* @returns {LoginCallbackParamsSuccess | LoginCallbackParamsError}
|
|
6
|
+
* @example // Success example:
|
|
7
|
+
HTTP/1.1 302 Found
|
|
8
|
+
Location: https://client.example.org/cb?code=abcd1234&state=0987poi&friendship_status_changed=true
|
|
9
|
+
* @example // Error example:
|
|
10
|
+
Location: https://example.com/callback?error=access_denied&error_description=The+resource+owner+denied+the+request.&state=0987poi
|
|
11
|
+
*/
|
|
12
|
+
export function getParamsFromLoginCallback(callbackUrlTriggered) {
|
|
13
|
+
const query = callbackUrlTriggered.split('?')[1];
|
|
14
|
+
const queryEntries = query?.split('&').map((q) => q.split('=')) ?? [];
|
|
15
|
+
const queryObject = Object.fromEntries(queryEntries);
|
|
16
|
+
return queryObject;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,98 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "line-ts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "LINE SDK for TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"module": "./dist/index.js",
|
|
9
|
-
"main": "./dist/index.js",
|
|
10
7
|
"exports": {
|
|
11
|
-
".":
|
|
12
|
-
"require": {
|
|
13
|
-
"types": "./dist/cjs/index.d.cts",
|
|
14
|
-
"default": "./dist/cjs/index.cjs"
|
|
15
|
-
},
|
|
16
|
-
"import": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"default": "./dist/index.js"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
8
|
+
".": "./dist/index.js"
|
|
21
9
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
],
|
|
25
10
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
11
|
+
"node": ">=18"
|
|
27
12
|
},
|
|
28
13
|
"scripts": {
|
|
29
|
-
"test": "echo
|
|
30
|
-
"lint": "tsc --noEmit && eslint ./src
|
|
31
|
-
"build": "
|
|
32
|
-
"release": "npm run lint &&
|
|
14
|
+
"test": "echo todo",
|
|
15
|
+
"lint": "tsc --noEmit && eslint ./src",
|
|
16
|
+
"build": "del-cli dist && tsc",
|
|
17
|
+
"release": "npm run lint && npm run build && np"
|
|
33
18
|
},
|
|
34
19
|
"devDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"del-cli": "^
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
42
|
-
"np": "^7.7.0",
|
|
43
|
-
"prettier": "^2.8.8",
|
|
44
|
-
"rollup": "^3.23.0",
|
|
45
|
-
"rollup-plugin-dts": "^5.3.0",
|
|
46
|
-
"rollup-plugin-esbuild": "^5.0.0",
|
|
47
|
-
"typescript": "^4.9.5",
|
|
48
|
-
"vitest": "^0.31.0"
|
|
20
|
+
"@cycraft/eslint": "^0.4.3",
|
|
21
|
+
"@cycraft/tsconfig": "^0.1.2",
|
|
22
|
+
"@types/jsonwebtoken": "^9.0.8",
|
|
23
|
+
"del-cli": "^6.0.0",
|
|
24
|
+
"np": "^10.2.0",
|
|
25
|
+
"vitest": "^3.0.6"
|
|
49
26
|
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
50
30
|
"keywords": [
|
|
51
31
|
"line",
|
|
52
32
|
"typescript",
|
|
53
33
|
"line-ts",
|
|
54
34
|
"line-sdk"
|
|
55
35
|
],
|
|
56
|
-
"author": "Luca Ban - Mesqueeb",
|
|
36
|
+
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
|
|
57
37
|
"funding": "https://github.com/sponsors/mesqueeb",
|
|
58
38
|
"license": "MIT",
|
|
59
|
-
"bugs": {
|
|
60
|
-
"url": "https://github.com/mesqueeb/line-ts/issues"
|
|
61
|
-
},
|
|
62
|
-
"homepage": "https://github.com/mesqueeb/line-ts#readme",
|
|
63
39
|
"repository": {
|
|
64
40
|
"type": "git",
|
|
65
|
-
"url": "
|
|
41
|
+
"url": "https://github.com/mesqueeb/line-ts.git"
|
|
66
42
|
},
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"branch": "production"
|
|
70
|
-
},
|
|
71
|
-
"eslintConfig": {
|
|
72
|
-
"ignorePatterns": [
|
|
73
|
-
"node_modules",
|
|
74
|
-
"dist",
|
|
75
|
-
"scripts",
|
|
76
|
-
"test"
|
|
77
|
-
],
|
|
78
|
-
"root": true,
|
|
79
|
-
"parser": "@typescript-eslint/parser",
|
|
80
|
-
"plugins": [
|
|
81
|
-
"@typescript-eslint",
|
|
82
|
-
"tree-shaking"
|
|
83
|
-
],
|
|
84
|
-
"extends": [
|
|
85
|
-
"eslint:recommended",
|
|
86
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
87
|
-
"plugin:@typescript-eslint/recommended",
|
|
88
|
-
"prettier"
|
|
89
|
-
],
|
|
90
|
-
"rules": {
|
|
91
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
92
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
93
|
-
"@typescript-eslint/ban-ts-ignore": "off",
|
|
94
|
-
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
95
|
-
"@typescript-eslint/ban-ts-comment": "off"
|
|
96
|
-
}
|
|
97
|
-
}
|
|
43
|
+
"homepage": "https://github.com/mesqueeb/line-ts#readme",
|
|
44
|
+
"bugs": "https://github.com/mesqueeb/line-ts/issues"
|
|
98
45
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function randomString(length = 20) {
|
|
4
|
-
return Array(length).fill(0).map(() => Math.random().toString(36).charAt(2)).join("");
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function getLineLoginUrl(params) {
|
|
8
|
-
const {
|
|
9
|
-
response_type = "code",
|
|
10
|
-
state = randomString(),
|
|
11
|
-
scope = "openid",
|
|
12
|
-
redirect_uri: _redirect_uri
|
|
13
|
-
} = params;
|
|
14
|
-
const redirect_uri = _redirect_uri.replace(/:/g, "%3A").replace(/\//g, "%2F");
|
|
15
|
-
const paramsObject = { ...params, response_type, redirect_uri, state, scope };
|
|
16
|
-
const query = Object.entries(paramsObject).map((entry) => entry.join("=")).join("&");
|
|
17
|
-
return `https://access.line.me/oauth2/v2.1/authorize?${query}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getParamsFromLoginCallback(callbackUrlTriggered) {
|
|
21
|
-
const query = callbackUrlTriggered.split("?")[1];
|
|
22
|
-
const queryEntries = query.split("&").map((q) => q.split("="));
|
|
23
|
-
const queryObject = Object.fromEntries(queryEntries);
|
|
24
|
-
return queryObject;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.getLineLoginUrl = getLineLoginUrl;
|
|
28
|
-
exports.getParamsFromLoginCallback = getParamsFromLoginCallback;
|