mirror of
https://github.com/ysoftdevs/oauth-playground-server.git
synced 2026-01-19 01:57:23 +01:00
test of Implicit flow
This commit is contained in:
@@ -50,10 +50,23 @@ public class AuthCodeGrantTest {
|
||||
flow.parseAndValidateRedirect(submit.connection().response());
|
||||
|
||||
assertThat(flow.getCode(), is(notNullValue()));
|
||||
assertThat(flow.getToken(), is(nullValue()));
|
||||
assertThat(flow.getAccessToken(), is(nullValue()));
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class AuthorizationCodeFlow {
|
||||
private final OAuthClient client;
|
||||
private String state = "testStateIsNotRandom";
|
||||
private String code;
|
||||
private String token;
|
||||
private String accessToken;
|
||||
private String idToken;
|
||||
|
||||
public AuthorizationCodeFlow(String authUrl, OAuthClient client) {
|
||||
@@ -64,10 +64,9 @@ public class AuthorizationCodeFlow {
|
||||
.stream().collect(Collectors.toMap(NameValuePair::getName, NameValuePair::getValue));
|
||||
|
||||
assertThat(query.get("state"), is(state));
|
||||
assertThat(query.get("code"), is(notNullValue()));
|
||||
|
||||
code = query.get("code");
|
||||
token = query.get("token");
|
||||
accessToken = query.get("access_token");
|
||||
idToken = query.get("id_token");
|
||||
}
|
||||
|
||||
@@ -87,7 +86,7 @@ public class AuthorizationCodeFlow {
|
||||
.body("access_token", is(notNullValue()))
|
||||
.body("refresh_token", is(notNullValue()))
|
||||
.extract().body().as(AccessTokenResponse.class);
|
||||
token = accessTokenResponse.accessToken();
|
||||
accessToken = accessTokenResponse.accessToken();
|
||||
idToken = accessTokenResponse.idToken();
|
||||
return accessTokenResponse;
|
||||
}
|
||||
@@ -100,8 +99,8 @@ public class AuthorizationCodeFlow {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
public String getIdToken() {
|
||||
|
||||
Reference in New Issue
Block a user