Skip to content

Commit

Permalink
Add sample for LINE Login
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Koleda authored May 30, 2019
1 parent 2d8880d commit 4f96652
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions samples/LINE.gs
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());
}

0 comments on commit 4f96652

Please sign in to comment.