-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-auth-server): new client config option defaultpromptlogin #979
- Loading branch information
Showing
7 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
jans-auth-server/client/src/test/java/io/jans/as/client/ws/rs/DefaultPromptLoginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Janssen Project software is available under the Apache License (2004). See http://www.apache.org/licenses/ for full text. | ||
* | ||
* Copyright (c) 2020, Janssen Project | ||
*/ | ||
|
||
package io.jans.as.client.ws.rs; | ||
|
||
import io.jans.as.client.*; | ||
import io.jans.as.client.client.Asserter; | ||
import io.jans.as.model.common.ResponseType; | ||
import io.jans.as.model.register.ApplicationType; | ||
import io.jans.as.model.util.StringUtils; | ||
import org.testng.annotations.Parameters; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static io.jans.as.model.register.RegisterRequestParam.*; | ||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
|
||
/** | ||
* @author Javier Rojas Blum | ||
* @version March 3, 2022 | ||
*/ | ||
public class DefaultPromptLoginTest extends BaseTest { | ||
|
||
@Parameters({"userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri"}) | ||
@Test | ||
public void defaultPromptLoginTrue( | ||
final String userId, final String userSecret, final String redirectUris, final String redirectUri, | ||
final String sectorIdentifierUri) { | ||
showTitle("defaultPromptLoginTrue"); | ||
|
||
List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN); | ||
|
||
// 1. Register client | ||
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", | ||
StringUtils.spaceSeparatedToList(redirectUris)); | ||
registerRequest.setResponseTypes(responseTypes); | ||
registerRequest.setSectorIdentifierUri(sectorIdentifierUri); | ||
registerRequest.setDefaultPromptLogin(true); | ||
|
||
RegisterClient registerClient = new RegisterClient(registrationEndpoint); | ||
registerClient.setRequest(registerRequest); | ||
RegisterResponse registerResponse = registerClient.exec(); | ||
|
||
showClient(registerClient); | ||
Asserter.assertRegisterResponseOk(registerResponse, 201, true); | ||
|
||
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()); | ||
Asserter.assertRegisterResponseOk(readClientResponse, 200, false); | ||
|
||
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(SCOPE.toString())); | ||
|
||
// 3. Request authorization | ||
List<String> scopes = Arrays.asList("openid", "profile", "address", "email"); | ||
String state = UUID.randomUUID().toString(); | ||
String nonce = UUID.randomUUID().toString(); | ||
|
||
String sessionId; | ||
{ | ||
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, | ||
redirectUri, nonce); | ||
authorizationRequest.setState(state); | ||
|
||
AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( | ||
authorizationEndpoint, authorizationRequest, userId, userSecret); | ||
|
||
Asserter.assertAuthorizationResponse(authorizationResponse, responseTypes, true); | ||
|
||
sessionId = authorizationResponse.getSessionId(); | ||
} | ||
|
||
{ | ||
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, | ||
redirectUri, nonce); | ||
authorizationRequest.setState(state); | ||
authorizationRequest.setSessionId(sessionId); | ||
|
||
AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess( | ||
authorizationEndpoint, authorizationRequest, userId, userSecret); | ||
|
||
Asserter.assertAuthorizationResponse(authorizationResponse, responseTypes, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters