Skip to content

Commit 4f96652

Browse files
author
Eric Koleda
authored
Add sample for LINE Login
1 parent 2d8880d commit 4f96652

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

samples/LINE.gs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* LINE Login Integration guide:
3+
* https://developers.line.biz/en/docs/line-login/web/integrate-line-login
4+
*/
5+
6+
// These are called Channel ID and Channel Secret in the console.
7+
var CLIENT_ID = '...';
8+
var CLIENT_SECRET = '...';
9+
10+
/**
11+
* Authorizes and makes a request to the Line API.
12+
*/
13+
function run() {
14+
var service = getService();
15+
if (service.hasAccess()) {
16+
var url = 'https://api.line.me/v2/profile';
17+
var response = UrlFetchApp.fetch(url, {
18+
headers: {
19+
Authorization: 'Bearer ' + service.getAccessToken()
20+
}
21+
});
22+
var result = JSON.parse(response.getContentText());
23+
Logger.log(JSON.stringify(result, null, 2));
24+
} else {
25+
var authorizationUrl = service.getAuthorizationUrl();
26+
Logger.log('Open the following URL and re-run the script: %s',
27+
authorizationUrl);
28+
}
29+
}
30+
31+
/**
32+
* Reset the authorization state, so that it can be re-tested.
33+
*/
34+
function reset() {
35+
getService().reset();
36+
}
37+
38+
/**
39+
* Configures the service.
40+
*/
41+
function getService() {
42+
return OAuth2.createService('LINE')
43+
// Set the endpoint URLs.
44+
.setAuthorizationBaseUrl('https://access.line.me/oauth2/v2.1/authorize')
45+
.setTokenUrl('https://api.line.me/oauth2/v2.1/token')
46+
47+
// Set the requested scopes (required).
48+
.setScope('profile')
49+
50+
// Set the client ID and secret.
51+
.setClientId(CLIENT_ID)
52+
.setClientSecret(CLIENT_SECRET)
53+
54+
// Set the name of the callback function that should be invoked to
55+
// complete the OAuth flow.
56+
.setCallbackFunction('authCallback')
57+
58+
// Set the property store where authorized tokens should be persisted.
59+
.setPropertyStore(PropertiesService.getUserProperties());
60+
}
61+
62+
/**
63+
* Handles the OAuth callback.
64+
*/
65+
function authCallback(request) {
66+
var service = getService();
67+
var authorized = service.handleCallback(request);
68+
if (authorized) {
69+
return HtmlService.createHtmlOutput('Success!');
70+
} else {
71+
return HtmlService.createHtmlOutput('Denied.');
72+
}
73+
}
74+
75+
/**
76+
* Logs the redict URI to register.
77+
*/
78+
function logRedirectUri() {
79+
Logger.log(OAuth2.getRedirectUri());
80+
}

0 commit comments

Comments
 (0)