File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const responses = {
8
8
instagram : { data : { id : 'userId' } } ,
9
9
janrainengage : { stat : 'ok' , profile : { identifier : 'userId' } } ,
10
10
janraincapture : { stat : 'ok' , result : 'userId' } ,
11
+ line : { userId : 'userId' } ,
11
12
vkontakte : { response : [ { id : 'userId' } ] } ,
12
13
google : { sub : 'userId' } ,
13
14
wechat : { errcode : 0 } ,
@@ -29,6 +30,7 @@ describe('AuthenticationProviders', function() {
29
30
'twitter' ,
30
31
'janrainengage' ,
31
32
'janraincapture' ,
33
+ 'line' ,
32
34
'vkontakte' ,
33
35
'qq' ,
34
36
'spotify' ,
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ const spotify = require('./spotify');
13
13
const digits = require ( './twitter' ) ; // digits tokens are validated by twitter
14
14
const janrainengage = require ( './janrainengage' ) ;
15
15
const janraincapture = require ( './janraincapture' ) ;
16
+ const line = require ( './line' ) ;
16
17
const vkontakte = require ( './vkontakte' ) ;
17
18
const qq = require ( './qq' ) ;
18
19
const wechat = require ( './wechat' ) ;
@@ -44,6 +45,7 @@ const providers = {
44
45
digits,
45
46
janrainengage,
46
47
janraincapture,
48
+ line,
47
49
vkontakte,
48
50
qq,
49
51
wechat,
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments