@@ -443,6 +443,51 @@ describe('AuthenticationProviders', function () {
443443 expect ( httpsRequest . get . calls . first ( ) . args [ 0 ] . includes ( 'appsecret_proof' ) ) . toBe ( true ) ;
444444 } ) ;
445445
446+ it ( 'should send the Facebook access token as a single request parameter' , async ( ) => {
447+ const crypto = require ( 'crypto' ) ;
448+ const httpsRequest = require ( '../lib/Adapters/Auth/httpsRequest' ) ;
449+ const requests = [ ] ;
450+ spyOn ( httpsRequest , 'get' ) . and . callFake ( url => {
451+ const requestUrl = new URL ( url ) ;
452+ requests . push ( requestUrl ) ;
453+ return Promise . resolve ( requestUrl . pathname === '/app' ? { id : 'appId' } : { id : 'userId' } ) ;
454+ } ) ;
455+ await reconfigureServer ( {
456+ auth : {
457+ facebook : {
458+ appIds : [ 'appId' ] ,
459+ appSecret : 'secret_sauce' ,
460+ } ,
461+ } ,
462+ } ) ;
463+ const access_token = 'token&fields=name#fragment' ;
464+ await request ( {
465+ method : 'POST' ,
466+ url : 'http://localhost:8378/1/users' ,
467+ headers : {
468+ 'Content-Type' : 'application/json' ,
469+ 'X-Parse-Application-Id' : 'test' ,
470+ 'X-Parse-REST-API-Key' : 'rest' ,
471+ } ,
472+ body : JSON . stringify ( { authData : { facebook : { id : 'userId' , access_token } } } ) ,
473+ } ) ;
474+ const appsecret_proof = crypto
475+ . createHmac ( 'sha256' , 'secret_sauce' )
476+ . update ( access_token )
477+ . digest ( 'hex' ) ;
478+ expect ( requests . map ( url => url . pathname ) ) . toEqual ( [ '/app' , '/me' ] ) ;
479+ expect ( [ ...requests [ 0 ] . searchParams ] ) . toEqual ( [
480+ [ 'access_token' , access_token ] ,
481+ [ 'appsecret_proof' , appsecret_proof ] ,
482+ ] ) ;
483+ expect ( [ ...requests [ 1 ] . searchParams ] ) . toEqual ( [
484+ [ 'fields' , 'id' ] ,
485+ [ 'access_token' , access_token ] ,
486+ [ 'appsecret_proof' , appsecret_proof ] ,
487+ ] ) ;
488+ expect ( requests . map ( url => url . hash ) ) . toEqual ( [ '' , '' ] ) ;
489+ } ) ;
490+
446491 it ( 'properly loads a custom adapter with options' , ( ) => {
447492 const options = {
448493 custom : {
@@ -1636,6 +1681,48 @@ describe('phant auth adapter', () => {
16361681 } ) ;
16371682} ) ;
16381683
1684+ describe ( 'vkontakte auth adapter' , ( ) => {
1685+ const httpsRequest = require ( '../lib/Adapters/Auth/httpsRequest' ) ;
1686+
1687+ it ( 'should send the access token as a single request parameter' , async ( ) => {
1688+ const options = {
1689+ vkontakte : {
1690+ enableInsecureAuth : true ,
1691+ appIds : [ 'appId' ] ,
1692+ appSecret : 'appSecret' ,
1693+ apiVersion : '5.131' ,
1694+ } ,
1695+ } ;
1696+ await reconfigureServer ( {
1697+ enableInsecureAuthAdapters : true ,
1698+ auth : options ,
1699+ } ) ;
1700+ const requests = [ ] ;
1701+ spyOn ( httpsRequest , 'get' ) . and . callFake ( url => {
1702+ const requestUrl = new URL ( url ) ;
1703+ requests . push ( requestUrl ) ;
1704+ return Promise . resolve (
1705+ requestUrl . hostname === 'oauth.vk.com'
1706+ ? { access_token : 'serviceToken' }
1707+ : { response : [ { id : 111 } ] }
1708+ ) ;
1709+ } ) ;
1710+ const authData = {
1711+ id : 111 ,
1712+ access_token : 'token&user_ids=222#fragment' ,
1713+ } ;
1714+ const { adapter, providerOptions } = authenticationLoader . loadAuthAdapter ( 'vkontakte' , options ) ;
1715+ await adapter . validateAuthData ( authData , providerOptions ) ;
1716+ const userRequest = requests . find ( url => url . hostname === 'api.vk.com' ) ;
1717+ expect ( userRequest . pathname ) . toBe ( '/method/users.get' ) ;
1718+ expect ( [ ...userRequest . searchParams ] ) . toEqual ( [
1719+ [ 'access_token' , 'token&user_ids=222#fragment' ] ,
1720+ [ 'v' , '5.131' ] ,
1721+ ] ) ;
1722+ expect ( userRequest . hash ) . toBe ( '' ) ;
1723+ } ) ;
1724+ } ) ;
1725+
16391726describe ( 'facebook limited auth adapter' , ( ) => {
16401727 const facebook = require ( '../lib/Adapters/Auth/facebook' ) ;
16411728 const jwt = require ( 'jsonwebtoken' ) ;
0 commit comments