@@ -214,58 +214,27 @@ private String authenticateAtOP(URI opAuthUri) throws Exception {
214214 assertThat (initResponse .getAsString ("type" ), equalTo ("auth" ));
215215 final String sid = initResponse .getAsString ("sid" );
216216 // Actually authenticate the user with ldapAuth
217- HttpPost loginHttpPost = new HttpPost (LOGIN_API + "authenticateSubject?cacheBuster=" + randomAlphaOfLength (8 ));
217+ HttpPost loginHttpPost = new HttpPost (
218+ LOGIN_API + "authenticateSubject?cacheBuster=" + randomAlphaOfLength (8 ) + "&authSessionId=" + sid
219+ );
218220 String loginJson = "{" + "\" username\" :\" alice\" ," + "\" password\" :\" secret\" " + "}" ;
219221 configureJsonRequest (loginHttpPost , loginJson );
220- JSONObject loginJsonResponse = execute (httpClient , loginHttpPost , context , response -> {
222+ execute (httpClient , loginHttpPost , context , response -> {
221223 assertHttpOk (response .getStatusLine ());
222224 return parseJsonResponse (response );
223225 });
224- // Get the consent screen
225- HttpPut consentFetchHttpPut = new HttpPut (
226- LOGIN_API + "updateAuthRequest" + "/" + sid + "?cacheBuster=" + randomAlphaOfLength (8 )
227- );
228- String consentFetchJson = "{"
229- + "\" sub\" : \" "
230- + loginJsonResponse .getAsString ("id" )
231- + "\" ,"
232- + "\" acr\" : \" http://loa.c2id.com/basic\" ,"
233- + "\" amr\" : [\" pwd\" ],"
234- + "\" data\" : {"
235- + "\" email\" : \" "
236- + loginJsonResponse .getAsString ("email" )
237- + "\" ,"
238- + "\" name\" : \" "
239- + loginJsonResponse .getAsString ("name" )
240- + "\" "
241- + "}"
242- + "}" ;
243- configureJsonRequest (consentFetchHttpPut , consentFetchJson );
244- JSONObject consentFetchResponse = execute (httpClient , consentFetchHttpPut , context , response -> {
226+
227+ HttpPut consentHttpPut = new HttpPut (LOGIN_API + "updateAuthRequest" + "/" + sid + "?cacheBuster=" + randomAlphaOfLength (8 ));
228+ String consentJson = "{" + "\" claims\" :[\" name\" , \" email\" ]," + "\" scope\" :[\" openid\" ]" + "}" ;
229+ configureJsonRequest (consentHttpPut , consentJson );
230+ JSONObject jsonConsentResponse = execute (httpClient , consentHttpPut , context , response -> {
245231 assertHttpOk (response .getStatusLine ());
246232 return parseJsonResponse (response );
247233 });
248- if (consentFetchResponse .getAsString ("type" ).equals ("consent" )) {
249- // If needed, submit the consent
250- HttpPut consentHttpPut = new HttpPut (
251- LOGIN_API + "updateAuthRequest" + "/" + sid + "?cacheBuster=" + randomAlphaOfLength (8 )
252- );
253- String consentJson = "{" + "\" claims\" :[\" name\" , \" email\" ]," + "\" scope\" :[\" openid\" ]" + "}" ;
254- configureJsonRequest (consentHttpPut , consentJson );
255- JSONObject jsonConsentResponse = execute (httpClient , consentHttpPut , context , response -> {
256- assertHttpOk (response .getStatusLine ());
257- return parseJsonResponse (response );
258- });
259- assertThat (jsonConsentResponse .getAsString ("type" ), equalTo ("response" ));
260- JSONObject parameters = (JSONObject ) jsonConsentResponse .get ("parameters" );
261- return parameters .getAsString ("uri" );
262- } else if (consentFetchResponse .getAsString ("type" ).equals ("response" )) {
263- JSONObject parameters = (JSONObject ) consentFetchResponse .get ("parameters" );
264- return parameters .getAsString ("uri" );
265- } else {
266- fail ("Received an invalid response from the OP" );
267- return null ;
268- }
234+ assertThat (jsonConsentResponse .getAsString ("type" ), equalTo ("response" ));
235+ JSONObject parameters = (JSONObject ) jsonConsentResponse .get ("parameters" );
236+ return parameters .getAsString ("uri" );
237+
269238 }
270239 }
271240
0 commit comments