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
This commit is contained in:
Saimoom Safayet Akash
2019-09-03 19:11:33 +06:00
committed by Diamond Lewis
parent 0e8779fbae
commit 723fe3b158
3 changed files with 43 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ const responses = {
instagram: { data: { id: 'userId' } },
janrainengage: { stat: 'ok', profile: { identifier: 'userId' } },
janraincapture: { stat: 'ok', result: 'userId' },
line: { userId: 'userId' },
vkontakte: { response: [{ id: 'userId' }] },
google: { sub: 'userId' },
wechat: { errcode: 0 },
@@ -29,6 +30,7 @@ describe('AuthenticationProviders', function() {
'twitter',
'janrainengage',
'janraincapture',
'line',
'vkontakte',
'qq',
'spotify',

View File

@@ -13,6 +13,7 @@ const spotify = require('./spotify');
const digits = require('./twitter'); // digits tokens are validated by twitter
const janrainengage = require('./janrainengage');
const janraincapture = require('./janraincapture');
const line = require('./line');
const vkontakte = require('./vkontakte');
const qq = require('./qq');
const wechat = require('./wechat');
@@ -44,6 +45,7 @@ const providers = {
digits,
janrainengage,
janraincapture,
line,
vkontakte,
qq,
wechat,

39
src/Adapters/Auth/line.js Normal file
View File

@@ -0,0 +1,39 @@
// Helper functions for accessing the line API.
var Parse = require('parse/node').Parse;
const httpsRequest = require('./httpsRequest');
// Returns a promise that fulfills if this user id is valid.
function validateAuthData(authData) {
return request('profile', authData.access_token).then(response => {
if (response && response.userId && response.userId === authData.id) {
return;
}
throw new Parse.Error(
Parse.Error.OBJECT_NOT_FOUND,
'Line auth is invalid for this user.'
);
});
}
// Returns a promise that fulfills iff this app id is valid.
function validateAppId() {
return Promise.resolve();
}
// A promisey wrapper for api requests
function request(path, access_token) {
var options = {
host: 'api.line.me',
path: '/v2/' + path,
method: 'GET',
headers: {
Authorization: 'Bearer ' + access_token,
},
};
return httpsRequest.get(options);
}
module.exports = {
validateAppId: validateAppId,
validateAuthData: validateAuthData,
};