@@ -334,4 +334,161 @@ public function testIssueStatelessChannelTokenByClientSecretAsyncWithHttpInfo():
334334 $ this ->assertEquals ('Bearer ' , $ response ->getTokenType ());
335335 $ this ->assertEquals (200 , $ statusCode );
336336 }
337+
338+ public function testIssueChannelToken (): void
339+ {
340+ $ client = Mockery::mock (ClientInterface::class);
341+ $ client ->shouldReceive ('send ' )
342+ ->with (
343+ Mockery::on (function (Request $ request ) {
344+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
345+ $ this ->assertEquals ('https://api.line.me/v2/oauth/accessToken ' , (string )$ request ->getUri ());
346+ $ body = (string )$ request ->getBody ();
347+ parse_str ($ body , $ params );
348+ // Must use snake_case keys from the OpenAPI spec
349+ $ this ->assertEquals ('client_credentials ' , $ params ['grant_type ' ]);
350+ $ this ->assertEquals ('1234 ' , $ params ['client_id ' ]);
351+ $ this ->assertEquals ('clientSecret ' , $ params ['client_secret ' ]);
352+ // Must NOT use camelCase keys
353+ $ this ->assertArrayNotHasKey ('grantType ' , $ params );
354+ $ this ->assertArrayNotHasKey ('clientId ' , $ params );
355+ $ this ->assertArrayNotHasKey ('clientSecret ' , $ params );
356+ return true ;
357+ }),
358+ []
359+ )
360+ ->once ()
361+ ->andReturn (new Response (
362+ status: 200 ,
363+ headers: [],
364+ body: json_encode (['access_token ' => 'accessToken ' , 'expires_in ' => 2592000 , 'token_type ' => 'Bearer ' ]),
365+ ));
366+ $ api = new ChannelAccessTokenApi ($ client );
367+ $ response = $ api ->issueChannelToken (grantType: 'client_credentials ' , clientId: '1234 ' , clientSecret: 'clientSecret ' );
368+ $ this ->assertEquals ('accessToken ' , $ response ->getAccessToken ());
369+ $ this ->assertEquals (2592000 , $ response ->getExpiresIn ());
370+ $ this ->assertEquals ('Bearer ' , $ response ->getTokenType ());
371+ }
372+
373+ public function testIssueChannelTokenByJWT (): void
374+ {
375+ $ client = Mockery::mock (ClientInterface::class);
376+ $ client ->shouldReceive ('send ' )
377+ ->with (
378+ Mockery::on (function (Request $ request ) {
379+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
380+ $ this ->assertEquals ('https://api.line.me/oauth2/v2.1/token ' , (string )$ request ->getUri ());
381+ $ body = (string )$ request ->getBody ();
382+ parse_str ($ body , $ params );
383+ // Must use snake_case keys from the OpenAPI spec
384+ $ this ->assertEquals ('client_credentials ' , $ params ['grant_type ' ]);
385+ $ this ->assertEquals ('urn:ietf:params:oauth:client-assertion-type:jwt-bearer ' , $ params ['client_assertion_type ' ]);
386+ $ this ->assertEquals ('jwtAssertionToken ' , $ params ['client_assertion ' ]);
387+ // Must NOT use camelCase keys
388+ $ this ->assertArrayNotHasKey ('grantType ' , $ params );
389+ $ this ->assertArrayNotHasKey ('clientAssertionType ' , $ params );
390+ $ this ->assertArrayNotHasKey ('clientAssertion ' , $ params );
391+ return true ;
392+ }),
393+ []
394+ )
395+ ->once ()
396+ ->andReturn (new Response (
397+ status: 200 ,
398+ headers: [],
399+ body: json_encode (['access_token ' => 'accessToken ' , 'expires_in ' => 2592000 , 'token_type ' => 'Bearer ' , 'key_id ' => 'keyId ' ]),
400+ ));
401+ $ api = new ChannelAccessTokenApi ($ client );
402+ $ response = $ api ->issueChannelTokenByJWT (
403+ grantType: 'client_credentials ' ,
404+ clientAssertionType: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer ' ,
405+ clientAssertion: 'jwtAssertionToken ' ,
406+ );
407+ $ this ->assertEquals ('accessToken ' , $ response ->getAccessToken ());
408+ $ this ->assertEquals (2592000 , $ response ->getExpiresIn ());
409+ $ this ->assertEquals ('Bearer ' , $ response ->getTokenType ());
410+ }
411+
412+ public function testRevokeChannelToken (): void
413+ {
414+ $ client = Mockery::mock (ClientInterface::class);
415+ $ client ->shouldReceive ('send ' )
416+ ->with (
417+ Mockery::on (function (Request $ request ) {
418+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
419+ $ this ->assertEquals ('https://api.line.me/v2/oauth/revoke ' , (string )$ request ->getUri ());
420+ $ body = (string )$ request ->getBody ();
421+ parse_str ($ body , $ params );
422+ // Must use snake_case key from the OpenAPI spec
423+ $ this ->assertEquals ('myAccessToken ' , $ params ['access_token ' ]);
424+ // Must NOT use camelCase key
425+ $ this ->assertArrayNotHasKey ('accessToken ' , $ params );
426+ return true ;
427+ }),
428+ []
429+ )
430+ ->once ()
431+ ->andReturn (new Response (status: 200 , headers: [], body: '' ));
432+ $ api = new ChannelAccessTokenApi ($ client );
433+ $ api ->revokeChannelToken (accessToken: 'myAccessToken ' );
434+ }
435+
436+ public function testRevokeChannelTokenByJWT (): void
437+ {
438+ $ client = Mockery::mock (ClientInterface::class);
439+ $ client ->shouldReceive ('send ' )
440+ ->with (
441+ Mockery::on (function (Request $ request ) {
442+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
443+ $ this ->assertEquals ('https://api.line.me/oauth2/v2.1/revoke ' , (string )$ request ->getUri ());
444+ $ body = (string )$ request ->getBody ();
445+ parse_str ($ body , $ params );
446+ // Must use snake_case keys from the OpenAPI spec
447+ $ this ->assertEquals ('1234 ' , $ params ['client_id ' ]);
448+ $ this ->assertEquals ('clientSecret ' , $ params ['client_secret ' ]);
449+ $ this ->assertEquals ('myAccessToken ' , $ params ['access_token ' ]);
450+ // Must NOT use camelCase keys
451+ $ this ->assertArrayNotHasKey ('clientId ' , $ params );
452+ $ this ->assertArrayNotHasKey ('clientSecret ' , $ params );
453+ $ this ->assertArrayNotHasKey ('accessToken ' , $ params );
454+ return true ;
455+ }),
456+ []
457+ )
458+ ->once ()
459+ ->andReturn (new Response (status: 200 , headers: [], body: '' ));
460+ $ api = new ChannelAccessTokenApi ($ client );
461+ $ api ->revokeChannelTokenByJWT (clientId: '1234 ' , clientSecret: 'clientSecret ' , accessToken: 'myAccessToken ' );
462+ }
463+
464+ public function testVerifyChannelToken (): void
465+ {
466+ $ client = Mockery::mock (ClientInterface::class);
467+ $ client ->shouldReceive ('send ' )
468+ ->with (
469+ Mockery::on (function (Request $ request ) {
470+ $ this ->assertEquals ('POST ' , $ request ->getMethod ());
471+ $ this ->assertEquals ('https://api.line.me/v2/oauth/verify ' , (string )$ request ->getUri ());
472+ $ body = (string )$ request ->getBody ();
473+ parse_str ($ body , $ params );
474+ // Must use snake_case key from the OpenAPI spec
475+ $ this ->assertEquals ('myAccessToken ' , $ params ['access_token ' ]);
476+ // Must NOT use camelCase key
477+ $ this ->assertArrayNotHasKey ('accessToken ' , $ params );
478+ return true ;
479+ }),
480+ []
481+ )
482+ ->once ()
483+ ->andReturn (new Response (
484+ status: 200 ,
485+ headers: [],
486+ body: json_encode (['client_id ' => '1234 ' , 'expires_in ' => 2592000 , 'scope ' => 'profile ' ]),
487+ ));
488+ $ api = new ChannelAccessTokenApi ($ client );
489+ $ response = $ api ->verifyChannelToken (accessToken: 'myAccessToken ' );
490+ $ this ->assertInstanceOf (VerifyChannelAccessTokenResponse::class, $ response );
491+ $ this ->assertEquals ('1234 ' , $ response ->getClientId ());
492+ $ this ->assertEquals (2592000 , $ response ->getExpiresIn ());
493+ }
337494}
0 commit comments