-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eric Koleda
authored
May 30, 2019
1 parent
2d8880d
commit 4f96652
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* LINE Login Integration guide: | ||
* https://developers.line.biz/en/docs/line-login/web/integrate-line-login | ||
*/ | ||
|
||
// These are called Channel ID and Channel Secret in the console. | ||
var CLIENT_ID = '...'; | ||
var CLIENT_SECRET = '...'; | ||
|
||
/** | ||
* Authorizes and makes a request to the Line API. | ||
*/ | ||
function run() { | ||
var service = getService(); | ||
if (service.hasAccess()) { | ||
var url = 'https://api.line.me/v2/profile'; | ||
var response = UrlFetchApp.fetch(url, { | ||
headers: { | ||
Authorization: 'Bearer ' + service.getAccessToken() | ||
} | ||
}); | ||
var result = JSON.parse(response.getContentText()); | ||
Logger.log(JSON.stringify(result, null, 2)); | ||
} else { | ||
var authorizationUrl = service.getAuthorizationUrl(); | ||
Logger.log('Open the following URL and re-run the script: %s', | ||
authorizationUrl); | ||
} | ||
} | ||
|
||
/** | ||
* Reset the authorization state, so that it can be re-tested. | ||
*/ | ||
function reset() { | ||
getService().reset(); | ||
} | ||
|
||
/** | ||
* Configures the service. | ||
*/ | ||
function getService() { | ||
return OAuth2.createService('LINE') | ||
// Set the endpoint URLs. | ||
.setAuthorizationBaseUrl('https://access.line.me/oauth2/v2.1/authorize') | ||
.setTokenUrl('https://api.line.me/oauth2/v2.1/token') | ||
|
||
// Set the requested scopes (required). | ||
.setScope('profile') | ||
|
||
// Set the client ID and secret. | ||
.setClientId(CLIENT_ID) | ||
.setClientSecret(CLIENT_SECRET) | ||
|
||
// Set the name of the callback function that should be invoked to | ||
// complete the OAuth flow. | ||
.setCallbackFunction('authCallback') | ||
|
||
// Set the property store where authorized tokens should be persisted. | ||
.setPropertyStore(PropertiesService.getUserProperties()); | ||
} | ||
|
||
/** | ||
* Handles the OAuth callback. | ||
*/ | ||
function authCallback(request) { | ||
var service = getService(); | ||
var authorized = service.handleCallback(request); | ||
if (authorized) { | ||
return HtmlService.createHtmlOutput('Success!'); | ||
} else { | ||
return HtmlService.createHtmlOutput('Denied.'); | ||
} | ||
} | ||
|
||
/** | ||
* Logs the redict URI to register. | ||
*/ | ||
function logRedirectUri() { | ||
Logger.log(OAuth2.getRedirectUri()); | ||
} |