@@ -54,6 +54,17 @@ func TestRedirectWithExistingGrant(t *testing.T) {
5454 assert .Truef (t , len (u .Query ().Get ("code" )) > 30 , "authorization code '%s' should be longer then 30" , u .Query ().Get ("code" ))
5555}
5656
57+ func TestAuthorizePKCERequiredForPublicClient (t * testing.T ) {
58+ defer tests .PrepareTestEnv (t )()
59+ req := NewRequest (t , "GET" , "/login/oauth/authorize?client_id=ce5a1322-42a7-11ed-b878-0242ac120002&redirect_uri=http%3A%2F%2F127.0.0.1&response_type=code&state=thestate" )
60+ ctx := loginUser (t , "user1" )
61+ resp := ctx .MakeRequest (t , req , http .StatusSeeOther )
62+ u , err := resp .Result ().Location ()
63+ assert .NoError (t , err )
64+ assert .Equal (t , "invalid_request" , u .Query ().Get ("error" ))
65+ assert .Equal (t , "PKCE is required for public clients" , u .Query ().Get ("error_description" ))
66+ }
67+
5768func TestAccessTokenExchange (t * testing.T ) {
5869 defer tests .PrepareTestEnv (t )()
5970 req := NewRequestWithValues (t , "POST" , "/login/oauth/access_token" , map [string ]string {
@@ -168,31 +179,6 @@ func TestAccessTokenExchangeWithInvalidCredentials(t *testing.T) {
168179 MakeRequest (t , req , http .StatusBadRequest )
169180}
170181
171- func TestAccessTokenExchangeForPublicClient (t * testing.T ) {
172- defer tests .PrepareTestEnv (t )()
173- req := NewRequestWithValues (t , "POST" , "/login/oauth/access_token" , map [string ]string {
174- "grant_type" : "authorization_code" ,
175- "client_id" : "ce5a1322-42a7-11ed-b878-0242ac120002" ,
176- "client_secret" : "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=" ,
177- // redirect port may vary
178- "redirect_uri" : "http://127.0.0.1:3456" ,
179- "code" : "authcodepublic" ,
180- "code_verifier" : "N1Zo9-8Rfwhkt68r1r29ty8YwIraXR8eh_1Qwxg7yQXsonBt" ,
181- })
182- MakeRequest (t , req , http .StatusOK )
183-
184- req = NewRequestWithValues (t , "POST" , "/login/oauth/access_token" , map [string ]string {
185- "grant_type" : "authorization_code" ,
186- "client_id" : "ce5a1322-42a7-11ed-b878-0242ac120002" ,
187- "client_secret" : "4MK8Na6R55smdCY0WuCCumZ6hjRPnGY5saWVRHHjJiA=" ,
188- // redirect port may vary
189- "redirect_uri" : "http://127.0.0.1:3456" ,
190- "code" : "authcodepublic" ,
191- // omit PKCE
192- })
193- MakeRequest (t , req , http .StatusBadRequest )
194- }
195-
196182func TestAccessTokenExchangeWithBasicAuth (t * testing.T ) {
197183 defer tests .PrepareTestEnv (t )()
198184 req := NewRequestWithValues (t , "POST" , "/login/oauth/access_token" , map [string ]string {
0 commit comments