FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JCL-469: Add support for scope, state and nonce values in the OpenIdProvider by acoburn · Pull Request #1376 · inrupt/solid-client-java · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
Expand Up @@ -54,8 +54,16 @@
*/
public class OpenIdProvider {

// OAuth 2 and OpenID request parameters
private static final String CLIENT_ID = "client_id";
private static final String CODE_CHALLENGE = "code_challenge";
private static final String CODE_CHALLENGE_METHOD = "code_challenge_method";
private static final String NONCE = "nonce";
private static final String REDIRECT_URI = "redirect_uri";
private static final String RESPONSE_TYPE = "response_type";
private static final String SCOPE = "scope";
private static final String STATE = "state";

private static final String EQUALS = "=";
private static final String ETC = "&";

Expand Down Expand Up @@ -155,11 +163,20 @@ private URI authorize(final URI authorizationEndpoint, final AuthorizationReques
final URIBuilder builder = URIBuilder.newBuilder(authorizationEndpoint)
.queryParam(CLIENT_ID, request.getClientId())
.queryParam(REDIRECT_URI, request.getRedirectUri().toString())
.queryParam("response_type", request.getResponseType());
.queryParam(RESPONSE_TYPE, request.getResponseType())
.queryParam(SCOPE, request.getScope());

if (request.getState() != null) {
builder.queryParam(STATE, request.getState());
}

if (request.getNonce() != null) {
builder.queryParam(NONCE, request.getNonce());
}

if (request.getCodeChallenge() != null && request.getCodeChallengeMethod() != null) {
builder.queryParam("code_challenge", request.getCodeChallenge());
builder.queryParam("code_challenge_method", request.getCodeChallengeMethod());
builder.queryParam(CODE_CHALLENGE, request.getCodeChallenge());
builder.queryParam(CODE_CHALLENGE_METHOD, request.getCodeChallengeMethod());
}

return builder.build();
Expand Down
This file contains hidden or 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
Expand Up @@ -83,6 +83,8 @@ void unknownMetadata() {
@Test
void authorizeAsyncTest() {
final AuthorizationRequest authReq = AuthorizationRequest.newBuilder()
.scope("openid")
.scope("webid")
.codeChallenge("myCodeChallenge")
.codeChallengeMethod("method")
.build(
Expand All @@ -91,7 +93,27 @@ void authorizeAsyncTest() {
);
assertEquals(
"http://example.test/auth?client_id=myClientId&redirect_uri=myRedirectUri&" +
"response_type=code&code_challenge=myCodeChallenge&code_challenge_method=method",
"response_type=code&scope=openid%20webid&code_challenge=myCodeChallenge&code_challenge_method=method",
openIdProvider.authorize(authReq).toCompletableFuture().join().toString()
);
}

@Test
void authorizeAsyncStateNonceTest() {
final String state = UUID.randomUUID().toString();
final String nonce = UUID.randomUUID().toString();
final AuthorizationRequest authReq = AuthorizationRequest.newBuilder()
.scope("openid")
.scope("webid")
.state(state)
.nonce(nonce)
.build(
"myClientId",
URI.create("myRedirectUri")
);
assertEquals(
"http://example.test/auth?client_id=myClientId&redirect_uri=myRedirectUri&" +
"response_type=code&scope=openid%20webid&state=" + state + "&nonce=" + nonce,
openIdProvider.authorize(authReq).toCompletableFuture().join().toString()
);
}
Expand Down

Back | FazBrowse Home | New Git URL