Java Code Examples for org.gluu.oxauth.model.crypto.OxAuthCryptoProvider#getPrivateKey()
The following examples show how to use
org.gluu.oxauth.model.crypto.OxAuthCryptoProvider#getPrivateKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 5 votes |
@Parameters({"keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void jwtStateAlgRSA15EncA256CBCPLUSHS512Test( final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("jwtStateAlgRSA15EncA256CBCPLUSHS512Test"); JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A256CBC_PLUS_HS512, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); assertNotNull(encodedState); System.out.println("Encrypted JWE State: " + encodedState); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(encodedState, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 2
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 5 votes |
@Parameters({"keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void jwtStateAlgRSA15EncA128CBCPLUSHS256Test( final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("jwtStateAlgRSA15EncA128CBCPLUSHS256Test"); JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A128CBC_PLUS_HS256, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); assertNotNull(encodedState); System.out.println("Encrypted JWE State: " + encodedState); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(encodedState, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 3
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 5 votes |
@Parameters({"keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void jwtStateAlgRSAOAEPEncA256GCMTest( final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("jwtStateAlgRSAOAEPEncA256GCMTest"); JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); assertNotNull(encodedState); System.out.println("Encrypted JWE State: " + encodedState); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(encodedState, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 4
Source File: CanProvideEncryptedIdTokenResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedIdTokenResponseAlgRSAOAEPEncA256GCM( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted ID Token Response RSA_OAEP A256GCM"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA_OAEP); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A256GCM); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String idToken = authorizationResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 5
Source File: TokenEncryptionHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "clientJwksUri", "RS256_enc_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) //@Test // Before run this test, set openidScopeBackwardCompatibility to true @Deprecated public void requestIdTokenAlgRSAOAEPEncA256GCM( final String userId, final String userSecret, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("requestIdTokenAlgRSAOAEPEncA256GCM"); List<GrantType> grantTypes = Arrays.asList( GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS ); // 1. Dynamic Client Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA_OAEP); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A256GCM); registerRequest.addCustomAttribute("oxAuthTrustedClient", "true"); registerRequest.setSectorIdentifierUri(sectorIdentifierUri); registerRequest.setGrantTypes(grantTypes); RegisterClient registerClient = new RegisterClient(registrationEndpoint); registerClient.setRequest(registerRequest); RegisterResponse response = registerClient.exec(); showClient(registerClient); assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity()); assertNotNull(response.getClientId()); assertNotNull(response.getClientSecret()); assertNotNull(response.getRegistrationAccessToken()); assertNotNull(response.getClientSecretExpiresAt()); String clientId = response.getClientId(); String clientSecret = response.getClientSecret(); // 2. Request authorization TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("openid"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec(); showClient(tokenClient); assertEquals(tokenResponse.getStatus(), 200, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getAccessToken(), "The access token is null"); assertNotNull(tokenResponse.getTokenType(), "The token type is null"); assertNotNull(tokenResponse.getRefreshToken(), "The refresh token is null"); assertNotNull(tokenResponse.getScope(), "The scope is null"); assertNotNull(tokenResponse.getIdToken(), "The id token is null"); String idToken = tokenResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.OX_OPENID_CONNECT_VERSION)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 6
Source File: CanProvideEncryptedIdTokenResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedIdTokenResponseAlgRSA15EncA256CBCPLUSHS512( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted ID Token Response RSA1_5 A256CBC_PLUS_HS512"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A256CBC_PLUS_HS512); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String idToken = authorizationResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 7
Source File: CanProvideEncryptedIdTokenResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedIdTokenResponseAlgRSA15EncA128CBCPLUSHS256( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted ID Token Response RSA1_5 A128CBC_PLUS_HS256"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String idToken = authorizationResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 8
Source File: CanProvideEncryptedUserInfoResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedUserInfoResponseAlgRSAOAEPEncA256GCM( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted UserInfo Response RSA_OAEP A256GCM"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA_OAEP); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A256GCM); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS).containsAll(Arrays.asList( JwtClaimName.ADDRESS_STREET_ADDRESS, JwtClaimName.ADDRESS_REGION, JwtClaimName.ADDRESS_LOCALITY, JwtClaimName.ADDRESS_COUNTRY))); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 9
Source File: CanProvideEncryptedUserInfoResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedUserInfoResponseAlgRSA15EncA256CBCPLUSHS512( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted UserInfo Response RSA1_5 A256CBC_PLUS_HS512"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A256CBC_PLUS_HS512); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS).containsAll(Arrays.asList( JwtClaimName.ADDRESS_STREET_ADDRESS, JwtClaimName.ADDRESS_REGION, JwtClaimName.ADDRESS_LOCALITY, JwtClaimName.ADDRESS_COUNTRY))); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 10
Source File: CanProvideEncryptedUserInfoResponse.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUri", "redirectUris", "clientJwksUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) @Test public void canProvideEncryptedUserInfoResponseAlgRSA15EncA128CBCPLUSHS256( final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("OC5:FeatureTest-Can Provide Encrypted UserInfo Response RSA1_5 A128CBC_PLUS_HS256"); List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Register client RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setJwksUri(jwksUri); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256); 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(); // 2. 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); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setRequest(authorizationRequest); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); UserInfoResponse userInfoResponse = userInfoClient.execUserInfo(accessToken); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ADDRESS).containsAll(Arrays.asList( JwtClaimName.ADDRESS_STREET_ADDRESS, JwtClaimName.ADDRESS_REGION, JwtClaimName.ADDRESS_LOCALITY, JwtClaimName.ADDRESS_COUNTRY))); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 11
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri", "keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void encodeClaimsInStateParameterAlgRSA15EncA256CBCPLUSHS512( final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri, final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("encodeClaimsInStateParameterAlgRSA15EncA256CBCPLUSHS512"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_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(); // 2. Request authorization JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); List<String> scopes = Arrays.asList("openid", "profile", "address", "email"); String nonce = UUID.randomUUID().toString(); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A256CBC_PLUS_HS512, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(encodedState); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String state = authorizationResponse.getState(); // 3. Decrypt state PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(state, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 12
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri", "keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void encodeClaimsInStateParameterAlgRSA15EncA128CBCPLUSHS256( final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri, final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("encodeClaimsInStateParameterAlgRSA15EncA128CBCPLUSHS256"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_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(); // 2. Request authorization JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); List<String> scopes = Arrays.asList("openid", "profile", "address", "email"); String nonce = UUID.randomUUID().toString(); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A128CBC_PLUS_HS256, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(encodedState); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String state = authorizationResponse.getState(); // 3. Decrypt state PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(state, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 13
Source File: EncodeClaimsInStateParameter.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri", "keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri"}) @Test public void encodeClaimsInStateParameterAlgRSAOAEPEncA256GCM( final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri, final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception { showTitle("encodeClaimsInStateParameterAlgRSAOAEPEncA256GCM"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_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(); // 2. Request authorization JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName); List<String> scopes = Arrays.asList("openid", "profile", "address", "email"); String nonce = UUID.randomUUID().toString(); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM, cryptoProvider); jwtState.setKeyId(keyId); jwtState.setRfp(rfp); jwtState.setJti(jti); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); String encodedState = jwtState.getEncodedJwt(jwks); AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(encodedState); AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( authorizationEndpoint, authorizationRequest, userId, userSecret); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The accessToken is null"); assertNotNull(authorizationResponse.getTokenType(), "The tokenType is null"); assertNotNull(authorizationResponse.getIdToken(), "The idToken is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); String state = authorizationResponse.getState(); // 3. Decrypt state PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(state, privateKey, null); assertNotNull(jwe.getClaims().getClaimAsString(KID)); assertNotNull(jwe.getClaims().getClaimAsString(RFP)); assertNotNull(jwe.getClaims().getClaimAsString(JTI)); assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS)); JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS); assertEquals(addClaims.getString("first_name"), "Javier"); assertEquals(addClaims.getString("last_name"), "Rojas"); assertEquals(addClaims.getInt("age"), 34); assertNotNull(addClaims.getJSONArray("more")); assertEquals(addClaims.getJSONArray("more").length(), 2); }
Example 14
Source File: UserInfoRestWebServiceHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"redirectUris", "redirectUri", "userId", "userSecret", "clientJwksUri", "sectorIdentifierUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret"}) @Test public void requestUserInfoAlgRSA15EncA256CBCPLUSHS512( final String redirectUris, final String redirectUri, final String userId, final String userSecret, final String jwksUri, final String sectorIdentifierUri, final String keyId, final String keyStoreFile, final String keyStoreSecret) { try { showTitle("requestUserInfoAlgRSA15EncA256CBCPLUSHS512"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Dynamic Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setResponseTypes(responseTypes); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A256CBC_PLUS_HS512); registerRequest.setSubjectType(SubjectType.PAIRWISE); 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.getClientSecretExpiresAt()); String clientId = registerResponse.getClientId(); AuthorizationResponse authorizationResponse = requestAuthorization(userId, userSecret, redirectUri, responseTypes, clientId); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info (encrypted) OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoRequest userInfoRequest = new UserInfoRequest(accessToken); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); userInfoClient.setRequest(userInfoRequest); UserInfoResponse userInfoResponse = userInfoClient.exec(); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 15
Source File: UserInfoRestWebServiceHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"redirectUris", "redirectUri", "userId", "userSecret", "clientJwksUri", "sectorIdentifierUri", "RSA1_5_keyId", "keyStoreFile", "keyStoreSecret"}) @Test public void requestUserInfoAlgRSA15EncA128CBCPLUSHS256( final String redirectUris, final String redirectUri, final String userId, final String userSecret, final String jwksUri, final String sectorIdentifierUri, final String keyId, final String keyStoreFile, final String keyStoreSecret) { try { showTitle("requestUserInfoAlgRSA15EncA128CBCPLUSHS256"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Dynamic Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setResponseTypes(responseTypes); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256); registerRequest.setSubjectType(SubjectType.PAIRWISE); 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.getClientSecretExpiresAt()); String clientId = registerResponse.getClientId(); AuthorizationResponse authorizationResponse = requestAuthorization(userId, userSecret, redirectUri, responseTypes, clientId); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info (encrypted) OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoRequest userInfoRequest = new UserInfoRequest(accessToken); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); userInfoClient.setRequest(userInfoRequest); UserInfoResponse userInfoResponse = userInfoClient.exec(); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 16
Source File: UserInfoRestWebServiceHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"redirectUris", "redirectUri", "userId", "userSecret", "clientJwksUri", "sectorIdentifierUri", "RSA_OAEP_keyId", "keyStoreFile", "keyStoreSecret"}) @Test public void requestUserInfoAlgRSAOAEPEncA256GCM( final String redirectUris, final String redirectUri, final String userId, final String userSecret, final String jwksUri, final String sectorIdentifierUri, final String keyId, final String keyStoreFile, final String keyStoreSecret) { try { showTitle("requestUserInfoAlgRSAOAEPEncA256GCM"); List<ResponseType> responseTypes = Arrays.asList( ResponseType.TOKEN, ResponseType.ID_TOKEN); // 1. Dynamic Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setResponseTypes(responseTypes); registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA_OAEP); registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A256GCM); registerRequest.setSubjectType(SubjectType.PAIRWISE); 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.getClientSecretExpiresAt()); String clientId = registerResponse.getClientId(); AuthorizationResponse authorizationResponse = requestAuthorization(userId, userSecret, redirectUri, responseTypes, clientId); String accessToken = authorizationResponse.getAccessToken(); // 3. Request user info (encrypted) OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); UserInfoRequest userInfoRequest = new UserInfoRequest(accessToken); UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint); userInfoClient.setPrivateKey(privateKey); userInfoClient.setRequest(userInfoRequest); UserInfoResponse userInfoResponse = userInfoClient.exec(); showClient(userInfoClient); assertEquals(userInfoResponse.getStatus(), 200, "Unexpected response code: " + userInfoResponse.getStatus()); assertNotNull(userInfoResponse.getClaim(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.GIVEN_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.FAMILY_NAME)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.PICTURE)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.EMAIL)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.ZONEINFO)); assertNotNull(userInfoResponse.getClaim(JwtClaimName.LOCALE)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 17
Source File: TokenEncryptionHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "clientJwksUri", "RS256_enc_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) //@Test // Before run this test, set openidScopeBackwardCompatibility to true @Deprecated public void requestIdTokenAlgRSA15EncA256CBCPLUSHS512( final String userId, final String userSecret, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("requestIdTokenAlgRSA15EncA256CBCPLUSHS512"); List<GrantType> grantTypes = Arrays.asList( GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS ); // 1. Dynamic Client Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A256CBC_PLUS_HS512); registerRequest.addCustomAttribute("oxAuthTrustedClient", "true"); registerRequest.setSectorIdentifierUri(sectorIdentifierUri); registerRequest.setGrantTypes(grantTypes); RegisterClient registerClient = new RegisterClient(registrationEndpoint); registerClient.setRequest(registerRequest); RegisterResponse response = registerClient.exec(); showClient(registerClient); assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity()); assertNotNull(response.getClientId()); assertNotNull(response.getClientSecret()); assertNotNull(response.getRegistrationAccessToken()); assertNotNull(response.getClientSecretExpiresAt()); String clientId = response.getClientId(); String clientSecret = response.getClientSecret(); // 2. Request authorization TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("openid"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec(); showClient(tokenClient); assertEquals(tokenResponse.getStatus(), 200, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getAccessToken(), "The access token is null"); assertNotNull(tokenResponse.getTokenType(), "The token type is null"); assertNotNull(tokenResponse.getRefreshToken(), "The refresh token is null"); assertNotNull(tokenResponse.getScope(), "The scope is null"); assertNotNull(tokenResponse.getIdToken(), "The id token is null"); String idToken = tokenResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.OX_OPENID_CONNECT_VERSION)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }
Example 18
Source File: TokenEncryptionHttpTest.java From oxAuth with MIT License | 4 votes |
@Parameters({"userId", "userSecret", "redirectUris", "clientJwksUri", "RS256_enc_keyId", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri"}) //@Test // Before run this test, set openidScopeBackwardCompatibility to true @Deprecated public void requestIdTokenAlgRSA15EncA128CBCPLUSHS256( final String userId, final String userSecret, final String redirectUris, final String jwksUri, final String keyId, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) { try { showTitle("requestIdTokenAlgRSA15EncA128CBCPLUSHS256"); List<GrantType> grantTypes = Arrays.asList( GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS ); // 1. Dynamic Client Registration RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setJwksUri(jwksUri); registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5); registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256); registerRequest.addCustomAttribute("oxAuthTrustedClient", "true"); registerRequest.setSectorIdentifierUri(sectorIdentifierUri); registerRequest.setGrantTypes(grantTypes); RegisterClient registerClient = new RegisterClient(registrationEndpoint); registerClient.setRequest(registerRequest); RegisterResponse response = registerClient.exec(); showClient(registerClient); assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity()); assertNotNull(response.getClientId()); assertNotNull(response.getClientSecret()); assertNotNull(response.getRegistrationAccessToken()); assertNotNull(response.getClientSecretExpiresAt()); String clientId = response.getClientId(); String clientSecret = response.getClientSecret(); // 2. Request authorization TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS); tokenRequest.setUsername(userId); tokenRequest.setPassword(userSecret); tokenRequest.setScope("openid"); tokenRequest.setAuthUsername(clientId); tokenRequest.setAuthPassword(clientSecret); TokenClient tokenClient = new TokenClient(tokenEndpoint); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec(); showClient(tokenClient); assertEquals(tokenResponse.getStatus(), 200, "Unexpected response code: " + tokenResponse.getStatus()); assertNotNull(tokenResponse.getEntity(), "The entity is null"); assertNotNull(tokenResponse.getAccessToken(), "The access token is null"); assertNotNull(tokenResponse.getTokenType(), "The token type is null"); assertNotNull(tokenResponse.getRefreshToken(), "The refresh token is null"); assertNotNull(tokenResponse.getScope(), "The scope is null"); assertNotNull(tokenResponse.getIdToken(), "The id token is null"); String idToken = tokenResponse.getIdToken(); // 3. Read Encrypted ID Token OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, null); PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId); Jwe jwe = Jwe.parse(idToken, privateKey, null); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.TYPE)); assertNotNull(jwe.getHeader().getClaimAsString(JwtHeaderName.ALGORITHM)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.AUDIENCE)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.EXPIRATION_TIME)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.ISSUED_AT)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER)); assertNotNull(jwe.getClaims().getClaimAsString(JwtClaimName.OX_OPENID_CONNECT_VERSION)); } catch (Exception ex) { fail(ex.getMessage(), ex); } }