test of Implicit flow

This commit is contained in:
Dusan Jakub
2023-09-18 16:29:02 +02:00
parent 641927387c
commit 744e7d3375
2 changed files with 20 additions and 8 deletions

View File

@@ -50,10 +50,23 @@ public class AuthCodeGrantTest {
flow.parseAndValidateRedirect(submit.connection().response()); flow.parseAndValidateRedirect(submit.connection().response());
assertThat(flow.getCode(), is(notNullValue())); assertThat(flow.getCode(), is(notNullValue()));
assertThat(flow.getToken(), is(nullValue())); assertThat(flow.getAccessToken(), is(nullValue()));
flow.exchangeCode(); flow.exchangeCode();
assertThat(flow.getToken(), is(notNullValue())); assertThat(flow.getAccessToken(), is(notNullValue()));
} }
@Test
public void implicitGrant() throws IOException {
AuthorizationCodeFlow flow = new AuthorizationCodeFlow(authUrl, CLIENT);
LoginScreen loginScreen = flow.start(Map.of("response_type", "token", "scope", "scope1 scope2"));
ConsentScreen consentScreen = loginScreen.submitCorrect("bob", "password");
assertThat(consentScreen.getScopes(), is(List.of("scope1", "scope2")));
Document submit = consentScreen.submit();
flow.parseAndValidateRedirect(submit.connection().response());
assertThat(flow.getAccessToken(), is(notNullValue()));
}
} }

View File

@@ -26,7 +26,7 @@ public class AuthorizationCodeFlow {
private final OAuthClient client; private final OAuthClient client;
private String state = "testStateIsNotRandom"; private String state = "testStateIsNotRandom";
private String code; private String code;
private String token; private String accessToken;
private String idToken; private String idToken;
public AuthorizationCodeFlow(String authUrl, OAuthClient client) { public AuthorizationCodeFlow(String authUrl, OAuthClient client) {
@@ -64,10 +64,9 @@ public class AuthorizationCodeFlow {
.stream().collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue)); .stream().collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
assertThat(query.get("state"), is(state)); assertThat(query.get("state"), is(state));
assertThat(query.get("code"), is(notNullValue()));
code = query.get("code"); code = query.get("code");
token = query.get("token"); accessToken = query.get("access_token");
idToken = query.get("id_token"); idToken = query.get("id_token");
} }
@@ -87,7 +86,7 @@ public class AuthorizationCodeFlow {
.body("access_token", is(notNullValue())) .body("access_token", is(notNullValue()))
.body("refresh_token", is(notNullValue())) .body("refresh_token", is(notNullValue()))
.extract().body().as(AccessTokenResponse.class); .extract().body().as(AccessTokenResponse.class);
token = accessTokenResponse.accessToken(); accessToken = accessTokenResponse.accessToken();
idToken = accessTokenResponse.idToken(); idToken = accessTokenResponse.idToken();
return accessTokenResponse; return accessTokenResponse;
} }
@@ -100,8 +99,8 @@ public class AuthorizationCodeFlow {
return code; return code;
} }
public String getToken() { public String getAccessToken() {
return token; return accessToken;
} }
public String getIdToken() { public String getIdToken() {