@@ -52,8 +52,8 @@ describe('oauth2', () => {
5252 var authorize = {
5353 code : 'code'
5454 }
55- var { body } = await oauth2 . access ( provider , authorize , { } )
56- t . deepEqual ( body , {
55+ var data = await oauth2 . access ( provider , authorize , { } )
56+ t . deepEqual ( data . raw , {
5757 grant_type : 'authorization_code' ,
5858 code : 'code' ,
5959 client_id : 'key' ,
@@ -252,14 +252,16 @@ describe('oauth2', () => {
252252 grant . config . visualstudio . access_url = url ( '/access_url' )
253253
254254 app . post ( '/access_url' , ( req , res ) => {
255- res . writeHead ( 200 , { 'content-type' : 'application/x-www-form-urlencoded' } )
256255 if ( req . headers . authorization ) {
256+ res . writeHead ( 200 , { 'content-type' : 'application/x-www-form-urlencoded' } )
257257 res . end ( qs . stringify ( { basic : req . headers . authorization } ) )
258258 }
259259 else if ( req . url . split ( '?' ) [ 1 ] ) {
260+ res . writeHead ( 200 , { 'content-type' : 'application/json' } )
260261 res . end ( qs . stringify ( req . query ) )
261262 }
262263 else if ( req . body ) {
264+ res . writeHead ( 200 , { 'content-type' : 'application/x-www-form-urlencoded' } )
263265 res . end ( qs . stringify ( req . body ) )
264266 }
265267 } )
@@ -268,30 +270,35 @@ describe('oauth2', () => {
268270
269271 describe ( 'web_server' , ( ) => {
270272 it ( 'basecamp' , async ( ) => {
271- var { body } = await oauth2 . access ( grant . config . basecamp , { code : 'code' } , { } )
272- t . equal ( body . type , 'web_server' )
273+ var data = await oauth2 . access ( grant . config . basecamp , { code : 'code' } , { } )
274+ t . equal ( data . raw . type , 'web_server' )
273275 } )
274276 } )
275277
276278 describe ( 'qs' , ( ) => {
277279 it ( 'concur' , async ( ) => {
278280 grant . config . concur . key = 'key'
279281 grant . config . concur . secret = 'secret'
280- var { body } = await oauth2 . access ( grant . config . concur , { code : 'code' } , { } )
281- t . deepEqual ( body , {
282+ var data = await oauth2 . access ( grant . config . concur , { code : 'code' } , { } )
283+ t . deepEqual ( qs . parse ( data . raw ) , {
282284 code : 'code' , client_id : 'key' , client_secret : 'secret'
283285 } )
284286 } )
287+ it ( 'surveymonkey' , async ( ) => {
288+ grant . config . surveymonkey . custom_params = { api_key : 'api_key' }
289+ var data = await oauth2 . access ( grant . config . surveymonkey , { code : 'code' } , { } )
290+ t . deepEqual ( qs . parse ( data . raw ) , { api_key : 'api_key' } )
291+ } )
285292 } )
286293
287294 describe ( 'basic auth' , ( ) => {
288295 ; [ 'ebay' , 'fitbit2' , 'homeaway' , 'reddit' ] . forEach ( ( provider ) => {
289296 it ( provider , async ( ) => {
290297 grant . config . ebay . key = 'key'
291298 grant . config . ebay . secret = 'secret'
292- var { body } = await oauth2 . access ( grant . config . ebay , { code : 'code' } , { } )
299+ var data = await oauth2 . access ( grant . config . ebay , { code : 'code' } , { } )
293300 t . deepEqual (
294- Buffer . from ( body . basic . replace ( 'Basic ' , '' ) , 'base64' ) . toString ( ) . split ( ':' ) ,
301+ Buffer . from ( data . raw . basic . replace ( 'Basic ' , '' ) , 'base64' ) . toString ( ) . split ( ':' ) ,
295302 [ 'key' , 'secret' ]
296303 )
297304 } )
@@ -300,24 +307,16 @@ describe('oauth2', () => {
300307
301308 describe ( 'hash' , ( ) => {
302309 it ( 'smartsheet' , async ( ) => {
303- var { body} = await oauth2 . access ( grant . config . smartsheet , { code : 'code' } , { } )
304- t . ok ( typeof body . hash === 'string' )
305- } )
306- } )
307-
308- describe ( 'api_key' , ( ) => {
309- it ( 'surveymonkey' , async ( ) => {
310- grant . config . surveymonkey . custom_params = { api_key : 'api_key' }
311- var { body} = await oauth2 . access ( grant . config . surveymonkey , { code : 'code' } , { } )
312- t . deepEqual ( body , { api_key : 'api_key' } )
310+ var data = await oauth2 . access ( grant . config . smartsheet , { code : 'code' } , { } )
311+ t . ok ( typeof data . raw . hash === 'string' )
313312 } )
314313 } )
315314
316315 describe ( 'Assertion Framework for OAuth 2.0' , ( ) => {
317316 it ( 'visualstudio' , async ( ) => {
318317 grant . config . visualstudio . secret = 'secret'
319- var { body } = await oauth2 . access ( grant . config . visualstudio , { code : 'code' } , { } )
320- t . deepEqual ( body , {
318+ var data = await oauth2 . access ( grant . config . visualstudio , { code : 'code' } , { } )
319+ t . deepEqual ( data . raw , {
321320 client_assertion_type : 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' ,
322321 client_assertion : 'secret' ,
323322 grant_type : 'urn:ietf:params:oauth:grant-type:jwt-bearer' ,
@@ -331,8 +330,8 @@ describe('oauth2', () => {
331330 it ( 'shopify' , async ( ) => {
332331 grant . config . shopify . access_url = url ( '/[subdomain]' )
333332 grant . config . shopify . subdomain = 'access_url'
334- var { body } = await oauth2 . access ( grant . config . shopify , { code : 'code' } , { } )
335- t . deepEqual ( body , {
333+ var data = await oauth2 . access ( grant . config . shopify , { code : 'code' } , { } )
334+ t . deepEqual ( data . raw , {
336335 grant_type : 'authorization_code' ,
337336 code : 'code' ,
338337 redirect_uri : url ( '/connect/shopify/callback' )
0 commit comments