Skip to content

Commit

Permalink
Restore backwards compatible of configuration constructor
Browse files Browse the repository at this point in the history
End-session support introduced a new parameter to
AuthorizationServiceConfiguration and broke backwards compatibility.
This change restores registrationEndpoint to 3rd position in constructor
and reintroduces the 3 parameter constructor.
  • Loading branch information
agologan committed Jan 18, 2021
1 parent 7aa9bf3 commit 907ebbd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,50 @@ public class AuthorizationServiceConfiguration {
public AuthorizationServiceConfiguration(
@NonNull Uri authorizationEndpoint,
@NonNull Uri tokenEndpoint) {
this(authorizationEndpoint, tokenEndpoint, null, null);
this(authorizationEndpoint, tokenEndpoint, null);
}

/**
* Creates a service configuration for a basic OAuth2 provider.
* @param authorizationEndpoint The
* @param authorizationEndpoint The
* [authorization endpoint URI](https://tools.ietf.org/html/rfc6749#section-3.1)
* for the service.
* @param tokenEndpoint The
* [token endpoint URI](https://tools.ietf.org/html/rfc6749#section-3.2)
* for the service.
* @param endSessionEndpoint The
* [end session endpoint URI](https://tools.ietf.org/html/rfc6749#section-2.2)
* for the service.
* @param registrationEndpoint The optional
* [client registration endpoint URI](https://tools.ietf.org/html/rfc7591#section-3)
*/
public AuthorizationServiceConfiguration(
@NonNull Uri authorizationEndpoint,
@NonNull Uri tokenEndpoint,
@Nullable Uri endSessionEndpoint,
@Nullable Uri registrationEndpoint) {
this(authorizationEndpoint, tokenEndpoint, registrationEndpoint, null);
}

/**
* Creates a service configuration for a basic OAuth2 provider.
* @param authorizationEndpoint The
* [authorization endpoint URI](https://tools.ietf.org/html/rfc6749#section-3.1)
* for the service.
* @param tokenEndpoint The
* [token endpoint URI](https://tools.ietf.org/html/rfc6749#section-3.2)
* for the service.
* @param registrationEndpoint The optional
* [client registration endpoint URI](https://tools.ietf.org/html/rfc7591#section-3)
* @param endSessionEndpoint The optional
* [end session endpoint URI](https://tools.ietf.org/html/rfc6749#section-2.2)
* for the service.
*/
public AuthorizationServiceConfiguration(
@NonNull Uri authorizationEndpoint,
@NonNull Uri tokenEndpoint,
@Nullable Uri registrationEndpoint,
@Nullable Uri endSessionEndpoint) {
this.authorizationEndpoint = checkNotNull(authorizationEndpoint);
this.tokenEndpoint = checkNotNull(tokenEndpoint);
this.endSessionEndpoint = endSessionEndpoint;
this.registrationEndpoint = registrationEndpoint;
this.endSessionEndpoint = endSessionEndpoint;
this.discoveryDoc = null;
}

Expand Down Expand Up @@ -162,10 +180,11 @@ public JSONObject toJson() {
if (registrationEndpoint != null) {
JsonUtil.put(json, KEY_REGISTRATION_ENDPOINT, registrationEndpoint.toString());
}
if (endSessionEndpoint != null) {
JsonUtil.put(json, KEY_END_SESSION_ENPOINT, endSessionEndpoint.toString());
}
if (discoveryDoc != null) {
JsonUtil.put(json, KEY_DISCOVERY_DOC, discoveryDoc.docJson);
} if (endSessionEndpoint != null) {
JsonUtil.put(json, KEY_END_SESSION_ENPOINT, endSessionEndpoint.toString());
}
return json;
}
Expand Down Expand Up @@ -204,9 +223,8 @@ public static AuthorizationServiceConfiguration fromJson(@NonNull JSONObject jso
return new AuthorizationServiceConfiguration(
JsonUtil.getUri(json, KEY_AUTHORIZATION_ENDPOINT),
JsonUtil.getUri(json, KEY_TOKEN_ENDPOINT),
JsonUtil.getUriIfDefined(json, KEY_END_SESSION_ENPOINT),
JsonUtil.getUriIfDefined(json,
KEY_REGISTRATION_ENDPOINT));
JsonUtil.getUriIfDefined(json, KEY_REGISTRATION_ENDPOINT),
JsonUtil.getUriIfDefined(json, KEY_END_SESSION_ENPOINT));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class AuthorizationServiceDiscovery {
static final UriField TOKEN_ENDPOINT = uri("token_endpoint");

@VisibleForTesting
static final UriField END_SESSION_ENPDINT = uri("end_session_endpoint");
static final UriField END_SESSION_ENDPOINT = uri("end_session_endpoint");

@VisibleForTesting
static final UriField USERINFO_ENDPOINT = uri("userinfo_endpoint");
Expand Down Expand Up @@ -265,7 +265,7 @@ public Uri getTokenEndpoint() {
* The OAuth 2 emd session endpoint URI. Not specified test OAuth implementation
*/
public Uri getEndSessionEndpoint() {
return get(END_SESSION_ENPDINT);
return get(END_SESSION_ENDPOINT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class AuthorizationServiceConfigurationTest {
+ " \"authorization_endpoint\": \"" + TEST_AUTH_ENDPOINT + "\",\n"
+ " \"token_endpoint\": \"" + TEST_TOKEN_ENDPOINT + "\",\n"
+ " \"registration_endpoint\": \"" + TEST_REGISTRATION_ENDPOINT + "\",\n"
+ " \"end_session_endpoint\": \"" + TEST_END_SESSION_ENDPOINT + "\",\n"
+ " \"userinfo_endpoint\": \"" + TEST_USERINFO_ENDPOINT + "\",\n"
+ " \"jwks_uri\": \"" + TEST_JWKS_URI + "\",\n"
+ " \"response_types_supported\": " + toJson(TEST_RESPONSE_TYPE_SUPPORTED) + ",\n"
Expand Down Expand Up @@ -117,8 +118,8 @@ public void setUp() throws Exception {
mConfig = new AuthorizationServiceConfiguration(
Uri.parse(TEST_AUTH_ENDPOINT),
Uri.parse(TEST_TOKEN_ENDPOINT),
Uri.parse(TEST_END_SESSION_ENDPOINT),
Uri.parse(TEST_REGISTRATION_ENDPOINT));
Uri.parse(TEST_REGISTRATION_ENDPOINT),
Uri.parse(TEST_END_SESSION_ENDPOINT));
when(mConnectionBuilder.openConnection(any(Uri.class))).thenReturn(mHttpConnection);
}

Expand All @@ -139,13 +140,14 @@ public void testSerializationWithoutRegistrationEndpoint() throws Exception {
AuthorizationServiceConfiguration config = new AuthorizationServiceConfiguration(
Uri.parse(TEST_AUTH_ENDPOINT),
Uri.parse(TEST_TOKEN_ENDPOINT),
Uri.parse(TEST_END_SESSION_ENDPOINT), null);
null,
Uri.parse(TEST_END_SESSION_ENDPOINT));
AuthorizationServiceConfiguration deserialized = AuthorizationServiceConfiguration
.fromJson(config.toJson());
assertThat(deserialized.authorizationEndpoint).isEqualTo(config.authorizationEndpoint);
assertThat(deserialized.tokenEndpoint).isEqualTo(config.tokenEndpoint);
assertThat(deserialized.endSessionEndpoint).isEqualTo(config.endSessionEndpoint);
assertThat(deserialized.registrationEndpoint).isNull();
assertThat(deserialized.endSessionEndpoint).isEqualTo(config.endSessionEndpoint);
}

@Test
Expand Down Expand Up @@ -183,6 +185,7 @@ private void assertMembers(AuthorizationServiceConfiguration config) {
assertEquals(TEST_AUTH_ENDPOINT, config.authorizationEndpoint.toString());
assertEquals(TEST_TOKEN_ENDPOINT, config.tokenEndpoint.toString());
assertEquals(TEST_REGISTRATION_ENDPOINT, config.registrationEndpoint.toString());
assertEquals(TEST_END_SESSION_ENDPOINT, config.endSessionEndpoint.toString());
}

@Test
Expand Down

0 comments on commit 907ebbd

Please sign in to comment.