mirror of
https://github.com/ysoftdevs/oauth-playground-server.git
synced 2026-03-29 13:31:56 +02:00
test of Implicit flow
This commit is contained in:
@@ -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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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() {
|
||||||
|
|||||||
Reference in New Issue
Block a user