@@ -1368,12 +1368,21 @@ describe.sequential("OAuth", () => {
13681368 expect ( responseBody . error ) . toBe ( "unsupported_grant_type" ) ;
13691369 } ) ;
13701370
1371- // Invalid request
1372- it ( "cannot use unknown parameters" , async ( ) => {
1373- expect . assertions ( 4 ) ;
1371+ it ( "can accept scope for authorization_code requests" , async ( ) => {
1372+ expect . assertions ( 7 ) ;
1373+
1374+ const accessGrant = await createAccessGrant (
1375+ application . id ,
1376+ account . id ,
1377+ [ "read:accounts" ] ,
1378+ OOB_REDIRECT_URI ,
1379+ ) ;
1380+
13741381 const body = new FormData ( ) ;
1375- body . set ( "grant_type" , "client_credentials " ) ;
1382+ body . set ( "grant_type" , "authorization_code " ) ;
13761383 body . set ( "redirect_uri" , OOB_REDIRECT_URI ) ;
1384+ body . set ( "code" , accessGrant . code ) ;
1385+ body . set ( "scope" , "follow" ) ;
13771386
13781387 const response = await app . request ( "/oauth/token" , {
13791388 method : "POST" ,
@@ -1383,13 +1392,44 @@ describe.sequential("OAuth", () => {
13831392 body,
13841393 } ) ;
13851394
1386- expect ( response . status ) . toBe ( 400 ) ;
1387- expect ( response . headers . get ( "content-type " ) ) . toBe ( "application/json" ) ;
1395+ expect ( response . status ) . toBe ( 200 ) ;
1396+ expect ( response . headers . get ( "Content-Type " ) ) . toBe ( "application/json" ) ;
13881397
13891398 const responseBody = await response . json ( ) ;
1399+ expect ( typeof responseBody ) . toBe ( "object" ) ;
1400+ expect ( responseBody ) . toHaveProperty ( "access_token" ) ;
1401+ expect ( responseBody ) . toHaveProperty ( "created_at" ) ;
1402+ expect ( responseBody . scope ) . toBe ( "read:accounts" ) ;
1403+ expect ( responseBody . token_type ) . toBe ( "Bearer" ) ;
1404+ } ) ;
13901405
1406+ it ( "can accept redirect_uri for client_credentials requests" , async ( ) => {
1407+ expect . assertions ( 7 ) ;
1408+
1409+ const body = new FormData ( ) ;
1410+ body . set ( "grant_type" , "client_credentials" ) ;
1411+ body . set ( "scope" , "read:accounts" ) ;
1412+ body . set ( "redirect_uri" , OOB_REDIRECT_URI ) ;
1413+
1414+ const response = await app . request ( "/oauth/token" , {
1415+ method : "POST" ,
1416+ headers : {
1417+ authorization : basicAuthorization ( application ) ,
1418+ } ,
1419+ body,
1420+ } ) ;
1421+
1422+ // No redirection happens here, since redirect_uri is not used in
1423+ // client_credentials flow, so we expect a 200 OK response:
1424+ expect ( response . status ) . toBe ( 200 ) ;
1425+ expect ( response . headers . get ( "Content-Type" ) ) . toBe ( "application/json" ) ;
1426+
1427+ const responseBody = await response . json ( ) ;
13911428 expect ( typeof responseBody ) . toBe ( "object" ) ;
1392- expect ( responseBody . error ) . toBe ( "invalid_request" ) ;
1429+ expect ( responseBody ) . toHaveProperty ( "access_token" ) ;
1430+ expect ( responseBody ) . toHaveProperty ( "created_at" ) ;
1431+ expect ( responseBody . scope ) . toBe ( "read:accounts" ) ;
1432+ expect ( responseBody . token_type ) . toBe ( "Bearer" ) ;
13931433 } ) ;
13941434 } ) ;
13951435
0 commit comments