use of io.jans.as.client.DeviceAuthzClient in project jans by JanssenProject.
the class DeviceAuthzFlowHttpTest method deviceAuthzFlow.
/**
* Device authorization complete flow.
*/
@Parameters({ "userId", "userSecret" })
@Test
public void deviceAuthzFlow(final String userId, final String userSecret) throws Exception {
showTitle("deviceAuthzFlow");
// 1. Init device authz request from WS
RegisterResponse registerResponse = DeviceAuthzRequestRegistrationTest.registerClientForDeviceAuthz(AuthenticationMethod.CLIENT_SECRET_BASIC, Collections.singletonList(GrantType.DEVICE_CODE), null, null, registrationEndpoint);
String clientId = registerResponse.getClientId();
String clientSecret = registerResponse.getClientSecret();
// 2. Device request registration
final List<String> scopes = Arrays.asList("openid", "profile", "address", "email", "phone", "user_name");
DeviceAuthzRequest deviceAuthzRequest = new DeviceAuthzRequest(clientId, scopes);
deviceAuthzRequest.setAuthUsername(clientId);
deviceAuthzRequest.setAuthPassword(clientSecret);
DeviceAuthzClient deviceAuthzClient = new DeviceAuthzClient(deviceAuthzEndpoint);
deviceAuthzClient.setRequest(deviceAuthzRequest);
DeviceAuthzResponse response = deviceAuthzClient.exec();
showClient(deviceAuthzClient);
DeviceAuthzRequestRegistrationTest.validateSuccessfulResponse(response);
// 3. Load device authz page, process user_code and authorization
WebDriver currentDriver = initWebDriver(false, true);
final PageConfig pageConfig = newPageConfig(currentDriver);
processDeviceAuthzPutUserCodeAndPressContinue(response.getUserCode(), currentDriver, false, pageConfig);
AuthorizationResponse authorizationResponse = processAuthorization(userId, userSecret, currentDriver);
stopWebDriver(false, currentDriver);
assertSuccessAuthzResponse(authorizationResponse);
// 4. Token request
TokenResponse tokenResponse1 = processTokens(clientId, clientSecret, response.getDeviceCode());
validateTokenSuccessfulResponse(tokenResponse1);
String refreshToken = tokenResponse1.getRefreshToken();
String idToken = tokenResponse1.getIdToken();
// 5. Validate id_token
verifyIdToken(idToken);
// 6. Request new access token using the refresh token.
TokenResponse tokenResponse2 = processNewTokenWithRefreshToken(StringUtils.implode(scopes, " "), refreshToken, clientId, clientSecret);
validateTokenSuccessfulResponse(tokenResponse2);
String accessToken = tokenResponse2.getAccessToken();
// 7. Request user info
processUserInfo(accessToken);
}
Aggregations