@@ -75,4 +75,102 @@ public function testRevokeChannelAccessToken()
7575 $ this ->assertTrue ($ res ->isSucceeded ());
7676 $ this ->assertEquals ([], $ res ->getJSONDecodedBody ());
7777 }
78+
79+ public function testCreateChannelAccessToken21 ()
80+ {
81+ $ mock = function ($ testRunner , $ httpMethod , $ url , $ data , $ header ) {
82+ /** @var \PHPUnit\Framework\TestCase $testRunner */
83+ $ testRunner ->assertEquals ('POST ' , $ httpMethod );
84+ $ testRunner ->assertEquals ('https://api.line.me/oauth2/v2.1/token ' , $ url );
85+ $ testRunner ->assertEquals ([
86+ 'grant_type ' => 'client_credentials ' ,
87+ 'client_assertion_type ' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer ' ,
88+ 'client_assertion ' => 'JWT ' ,
89+ ], $ data );
90+ $ testRunner ->assertEquals (['Content-Type: application/x-www-form-urlencoded ' ], $ header );
91+
92+ return [
93+ 'access_token ' => 'W1TeHCgfH2Liwa..... ' ,
94+ 'expires_in ' => 2592000 ,
95+ 'token_type ' => 'Bearer ' ,
96+ 'key_id ' => 'sDTOzw5wIfxxxxPEzcmeQA ' ,
97+ ];
98+ };
99+ $ bot = new LINEBot (new DummyHttpClient ($ this , $ mock ), ['channelSecret ' => 'CHANNEL-SECRET ' ]);
100+
101+ $ res = $ bot ->createChannelAccessToken21 ('JWT ' );
102+
103+ $ this ->assertEquals (200 , $ res ->getHTTPStatus ());
104+ $ this ->assertTrue ($ res ->isSucceeded ());
105+
106+ $ data = $ res ->getJSONDecodedBody ();
107+ $ this ->assertEquals ('W1TeHCgfH2Liwa..... ' , $ data ['access_token ' ]);
108+ $ this ->assertEquals (2592000 , $ data ['expires_in ' ]);
109+ $ this ->assertEquals ('Bearer ' , $ data ['token_type ' ]);
110+ $ this ->assertEquals ('sDTOzw5wIfxxxxPEzcmeQA ' , $ data ['key_id ' ]);
111+ }
112+
113+ public function testRevokeChannelAccessToken21 ()
114+ {
115+ $ mock = function ($ testRunner , $ httpMethod , $ url , $ data , $ header ) {
116+ /** @var \PHPUnit\Framework\TestCase $testRunner */
117+ $ testRunner ->assertEquals ('POST ' , $ httpMethod );
118+ $ testRunner ->assertEquals ('https://api.line.me/oauth2/v2.1/revoke ' , $ url );
119+ $ testRunner ->assertEquals ([
120+ 'client_id ' => 'CHANNEL-ID ' ,
121+ 'client_secret ' => 'CHANNEL-SECRET ' ,
122+ 'access_token ' => 'CHANNEL-ACCESS-TOKEN '
123+ ], $ data );
124+ $ testRunner ->assertEquals (['Content-Type: application/x-www-form-urlencoded ' ], $ header );
125+
126+ return [];
127+ };
128+ $ bot = new LINEBot (new DummyHttpClient ($ this , $ mock ), ['channelSecret ' => 'CHANNEL-SECRET ' ]);
129+
130+ $ res = $ bot ->revokeChannelAccessToken21 ('CHANNEL-ID ' , 'CHANNEL-SECRET ' , 'CHANNEL-ACCESS-TOKEN ' );
131+
132+ $ this ->assertEquals (200 , $ res ->getHTTPStatus ());
133+ $ this ->assertTrue ($ res ->isSucceeded ());
134+ $ this ->assertEquals ([], $ res ->getJSONDecodedBody ());
135+ }
136+
137+ public function testGetChannelAccessToken21Keys1 ()
138+ {
139+ $ mock = function ($ testRunner , $ httpMethod , $ url , $ data ) {
140+ /** @var \PHPUnit\Framework\TestCase $testRunner */
141+ $ testRunner ->assertEquals ('GET ' , $ httpMethod );
142+ $ testRunner ->assertEquals ('https://api.line.me/oauth2/v2.1/tokens/kid ' , $ url );
143+ $ testRunner ->assertEquals ([
144+ 'client_assertion_type ' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer ' ,
145+ 'client_assertion ' => 'JWT ' ,
146+ ], $ data );
147+
148+ return [
149+ 'key_ids ' => [
150+ 'U_gdnFYKTWRxxxxDVZexGg ' ,
151+ 'sDTOzw5wIfWxxxxzcmeQA ' ,
152+ '73hDyp3PxGfxxxxD6U5qYA ' ,
153+ 'FHGanaP79smDxxxxyPrVw ' ,
154+ 'CguB-0kxxxxdSM3A5Q_UtQ ' ,
155+ 'G82YP96jhHwyKSxxxx7IFA ' ,
156+ ]
157+ ];
158+ };
159+ $ bot = new LINEBot (new DummyHttpClient ($ this , $ mock ), ['channelSecret ' => 'CHANNEL-SECRET ' ]);
160+
161+ $ res = $ bot ->getChannelAccessToken21Keys ('JWT ' );
162+
163+ $ this ->assertEquals (200 , $ res ->getHTTPStatus ());
164+ $ this ->assertTrue ($ res ->isSucceeded ());
165+
166+ $ data = $ res ->getJSONDecodedBody ();
167+ $ this ->assertEquals ([
168+ 'U_gdnFYKTWRxxxxDVZexGg ' ,
169+ 'sDTOzw5wIfWxxxxzcmeQA ' ,
170+ '73hDyp3PxGfxxxxD6U5qYA ' ,
171+ 'FHGanaP79smDxxxxyPrVw ' ,
172+ 'CguB-0kxxxxdSM3A5Q_UtQ ' ,
173+ 'G82YP96jhHwyKSxxxx7IFA ' ,
174+ ], $ data ['key_ids ' ]);
175+ }
78176}
0 commit comments