Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenate JWKS path with existing path on domain if present #67

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/com/auth0/jwk/UrlJwkProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.*;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -80,9 +78,9 @@ static URL urlForDomain(String domain) {
}

try {
final URL url = new URL(domain);
return new URL(url, WELL_KNOWN_JWKS_PATH);
} catch (MalformedURLException e) {
final URI uri = new URI(domain + WELL_KNOWN_JWKS_PATH).normalize();
return uri.toURL();
} catch (MalformedURLException | URISyntaxException e) {
throw new IllegalArgumentException("Invalid jwks uri", e);
}
}
Expand Down
28 changes: 26 additions & 2 deletions src/test/java/com/auth0/jwk/UrlJwkProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,35 @@ public void shouldBuildCorrectHttpUrlOnDomainWithHttpAndSlash() {
}

@Test
public void shouldUseOnlyDomain() {
public void shouldUseDomainAndPathWithSlashIfPresent() {
String domain = "samples.auth0.com";
String domainWithSubPath = domain + "/sub/path/";
String actualJwksUrl = new UrlJwkProvider(domainWithSubPath).url.toString();
assertThat(actualJwksUrl, equalTo("https://" + domain + WELL_KNOWN_JWKS_PATH));
assertThat(actualJwksUrl, equalTo("https://" + domain + "/sub/path" + WELL_KNOWN_JWKS_PATH));
}

@Test
public void shouldUseDomainAndPathWithoutSlashIfPresent() {
String domain = "samples.auth0.com";
String domainWithSubPath = domain + "/sub/path";
String actualJwksUrl = new UrlJwkProvider(domainWithSubPath).url.toString();
assertThat(actualJwksUrl, equalTo("https://" + domain + "/sub/path" + WELL_KNOWN_JWKS_PATH));
}

@Test
public void shouldUseDomainAndSinglePathWithSlashIfPresent() {
String domain = "samples.auth0.com";
String domainWithSubPath = domain + "/path/";
String actualJwksUrl = new UrlJwkProvider(domainWithSubPath).url.toString();
assertThat(actualJwksUrl, equalTo("https://" + domain + "/path" + WELL_KNOWN_JWKS_PATH));
}

@Test
public void shouldUseDomainAndSinglePathWithoutSlashIfPresent() {
String domain = "samples.auth0.com";
String domainWithSubPath = domain + "/path";
String actualJwksUrl = new UrlJwkProvider(domainWithSubPath).url.toString();
assertThat(actualJwksUrl, equalTo("https://" + domain + "/path" + WELL_KNOWN_JWKS_PATH));
}

@Test
Expand Down