Skip to content

Commit 723fe3b

Browse files
ssafayetdplewis
authored andcommitted
added support for line auth (#6007)
* added support for line auth * fixed linting issues * modified auth adapter spec to handle line auth adapter * revert package.json changes
1 parent 0e8779f commit 723fe3b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

spec/AuthenticationAdapters.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const responses = {
88
instagram: { data: { id: 'userId' } },
99
janrainengage: { stat: 'ok', profile: { identifier: 'userId' } },
1010
janraincapture: { stat: 'ok', result: 'userId' },
11+
line: { userId: 'userId' },
1112
vkontakte: { response: [{ id: 'userId' }] },
1213
google: { sub: 'userId' },
1314
wechat: { errcode: 0 },
@@ -29,6 +30,7 @@ describe('AuthenticationProviders', function() {
2930
'twitter',
3031
'janrainengage',
3132
'janraincapture',
33+
'line',
3234
'vkontakte',
3335
'qq',
3436
'spotify',

src/Adapters/Auth/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const spotify = require('./spotify');
1313
const digits = require('./twitter'); // digits tokens are validated by twitter
1414
const janrainengage = require('./janrainengage');
1515
const janraincapture = require('./janraincapture');
16+
const line = require('./line');
1617
const vkontakte = require('./vkontakte');
1718
const qq = require('./qq');
1819
const wechat = require('./wechat');
@@ -44,6 +45,7 @@ const providers = {
4445
digits,
4546
janrainengage,
4647
janraincapture,
48+
line,
4749
vkontakte,
4850
qq,
4951
wechat,

src/Adapters/Auth/line.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Helper functions for accessing the line API.
2+
var Parse = require('parse/node').Parse;
3+
const httpsRequest = require('./httpsRequest');
4+
5+
// Returns a promise that fulfills if this user id is valid.
6+
function validateAuthData(authData) {
7+
return request('profile', authData.access_token).then(response => {
8+
if (response && response.userId && response.userId === authData.id) {
9+
return;
10+
}
11+
throw new Parse.Error(
12+
Parse.Error.OBJECT_NOT_FOUND,
13+
'Line auth is invalid for this user.'
14+
);
15+
});
16+
}
17+
18+
// Returns a promise that fulfills iff this app id is valid.
19+
function validateAppId() {
20+
return Promise.resolve();
21+
}
22+
23+
// A promisey wrapper for api requests
24+
function request(path, access_token) {
25+
var options = {
26+
host: 'api.line.me',
27+
path: '/v2/' + path,
28+
method: 'GET',
29+
headers: {
30+
Authorization: 'Bearer ' + access_token,
31+
},
32+
};
33+
return httpsRequest.get(options);
34+
}
35+
36+
module.exports = {
37+
validateAppId: validateAppId,
38+
validateAuthData: validateAuthData,
39+
};

0 commit comments

Comments
 (0)