/* * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text. * * Copyright (c) 2014, Gluu */ package org.xdi.oxauth.ws.rs; import org.testng.annotations.Parameters; import org.testng.annotations.Test; import org.xdi.oxauth.BaseTest; import org.xdi.oxauth.client.*; import org.xdi.oxauth.model.common.ResponseType; import org.xdi.oxauth.model.register.ApplicationType; import org.xdi.oxauth.model.util.StringUtils; import java.util.Arrays; import java.util.List; import java.util.UUID; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.xdi.oxauth.model.register.RegisterRequestParam.*; /** * @author Javier Rojas Blum * @version November 2, 2016 */ public class UILocales extends BaseTest { @Parameters({"userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri"}) @Test public void uiLocales( final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri) throws Exception { showTitle("uiLocales"); //List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setSectorIdentifierUri(sectorIdentifierUri); RegisterClient registerClient = new RegisterClient(registrationEndpoint); registerClient.setRequest(registerRequest); RegisterResponse registerResponse = registerClient.exec(); showClient(registerClient); assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity()); assertNotNull(registerResponse.getClientId()); assertNotNull(registerResponse.getClientSecret()); assertNotNull(registerResponse.getRegistrationAccessToken()); assertNotNull(registerResponse.getClientIdIssuedAt()); assertNotNull(registerResponse.getClientSecretExpiresAt()); String clientId = registerResponse.getClientId(); String registrationAccessToken = registerResponse.getRegistrationAccessToken(); String registrationClientUri = registerResponse.getRegistrationClientUri(); // 2. Client read RegisterRequest readClientRequest = new RegisterRequest(registrationAccessToken); RegisterClient readClient = new RegisterClient(registrationClientUri); readClient.setRequest(readClientRequest); RegisterResponse readClientResponse = readClient.exec(); showClient(readClient); assertEquals(readClientResponse.getStatus(), 200, "Unexpected response code: " + readClientResponse.getEntity()); assertNotNull(readClientResponse.getClientId()); assertNotNull(readClientResponse.getClientSecret()); assertNotNull(readClientResponse.getClientIdIssuedAt()); assertNotNull(readClientResponse.getClientSecretExpiresAt()); assertNotNull(readClientResponse.getClaims().get(RESPONSE_TYPES.toString())); assertNotNull(readClientResponse.getClaims().get(REDIRECT_URIS.toString())); assertNotNull(readClientResponse.getClaims().get(APPLICATION_TYPE.toString())); assertNotNull(readClientResponse.getClaims().get(CLIENT_NAME.toString())); assertNotNull(readClientResponse.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString())); assertNotNull(readClientResponse.getClaims().get("scopes")); // 3. Request authorization List<String> scopes = Arrays.asList("openid", "profile", "address", "email"); String nonce = UUID.randomUUID().toString(); String state = UUID.randomUUID().toString(); AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(state); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The access token is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); assertNotNull(authorizationResponse.getTokenType(), "The token type is null"); assertNotNull(authorizationResponse.getExpiresIn(), "The expires in value is null"); assertNotNull(authorizationResponse.getScope(), "The scope must be null"); } }