@@ -136,59 +136,30 @@ protected String authenticateAtOP(URI opAuthUri) throws Exception {
136
136
assertThat (initResponse .getAsString ("type" ), equalTo ("auth" ));
137
137
final String sid = initResponse .getAsString ("sid" );
138
138
// Actually authenticate the user with ldapAuth
139
- HttpPost loginHttpPost = new HttpPost (C2ID_LOGIN_API + "authenticateSubject?cacheBuster=" + randomAlphaOfLength (8 ));
139
+ HttpPost loginHttpPost = new HttpPost (
140
+ C2ID_LOGIN_API + "authenticateSubject?cacheBuster=" + randomAlphaOfLength (8 ) + "&authSessionId=" + sid
141
+ );
140
142
String loginJson = """
141
143
{"username":"alice","password":"secret"}""" ;
142
144
configureJsonRequest (loginHttpPost , loginJson );
143
- JSONObject loginJsonResponse = execute (httpClient , loginHttpPost , context , response -> {
145
+ execute (httpClient , loginHttpPost , context , response -> {
144
146
assertHttpOk (response .getStatusLine ());
145
147
return parseJsonResponse (response );
146
148
});
147
- // Get the consent screen
148
- HttpPut consentFetchHttpPut = new HttpPut (
149
+
150
+ HttpPut consentHttpPut = new HttpPut (
149
151
C2ID_LOGIN_API + "updateAuthRequest" + "/" + sid + "?cacheBuster=" + randomAlphaOfLength (8 )
150
152
);
151
- String consentFetchJson = """
152
- {
153
- "sub": "%s",
154
- "acr": "http://loa.c2id.com/basic",
155
- "amr": [ "pwd" ],
156
- "data": {
157
- "email": "%s",
158
- "name": "%s"
159
- }
160
- }""" .formatted (
161
- loginJsonResponse .getAsString ("id" ),
162
- loginJsonResponse .getAsString ("email" ),
163
- loginJsonResponse .getAsString ("name" )
164
- );
165
- configureJsonRequest (consentFetchHttpPut , consentFetchJson );
166
- JSONObject consentFetchResponse = execute (httpClient , consentFetchHttpPut , context , response -> {
153
+ String consentJson = """
154
+ {"claims":["name", "email"],"scope":["openid"]}""" ;
155
+ configureJsonRequest (consentHttpPut , consentJson );
156
+ JSONObject jsonConsentResponse = execute (httpClient , consentHttpPut , context , response -> {
167
157
assertHttpOk (response .getStatusLine ());
168
158
return parseJsonResponse (response );
169
159
});
170
- if (consentFetchResponse .getAsString ("type" ).equals ("consent" )) {
171
- // If needed, submit the consent
172
- HttpPut consentHttpPut = new HttpPut (
173
- C2ID_LOGIN_API + "updateAuthRequest" + "/" + sid + "?cacheBuster=" + randomAlphaOfLength (8 )
174
- );
175
- String consentJson = """
176
- {"claims":["name", "email"],"scope":["openid"]}""" ;
177
- configureJsonRequest (consentHttpPut , consentJson );
178
- JSONObject jsonConsentResponse = execute (httpClient , consentHttpPut , context , response -> {
179
- assertHttpOk (response .getStatusLine ());
180
- return parseJsonResponse (response );
181
- });
182
- assertThat (jsonConsentResponse .getAsString ("type" ), equalTo ("response" ));
183
- JSONObject parameters = (JSONObject ) jsonConsentResponse .get ("parameters" );
184
- return parameters .getAsString ("uri" );
185
- } else if (consentFetchResponse .getAsString ("type" ).equals ("response" )) {
186
- JSONObject parameters = (JSONObject ) consentFetchResponse .get ("parameters" );
187
- return parameters .getAsString ("uri" );
188
- } else {
189
- fail ("Received an invalid response from the OP" );
190
- return null ;
191
- }
160
+ assertThat (jsonConsentResponse .getAsString ("type" ), equalTo ("response" ));
161
+ JSONObject parameters = (JSONObject ) jsonConsentResponse .get ("parameters" );
162
+ return parameters .getAsString ("uri" );
192
163
}
193
164
}
194
165
0 commit comments