com.auth0.jwk.UrlJwkProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jwks-rsa Show documentation
Show all versions of jwks-rsa Show documentation
JSON Web Key Set parser library
package com.auth0.jwk;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
/**
* Jwk provider that loads them from a {@link URL}
*/
@SuppressWarnings("WeakerAccess")
public class UrlJwkProvider implements JwkProvider {
final URL url;
/**
* Creates a provider that loads from a given URL
* @param url to load the jwks
*/
public UrlJwkProvider(URL url) {
if (url == null) {
throw new IllegalArgumentException("A non-null url is required");
}
this.url = url;
}
/**
* Creates a provider that loads from the given domain's well-known directory
* @param domain domain where to look for the jwks.json file
*/
public UrlJwkProvider(String domain) {
if (Strings.isNullOrEmpty(domain)) {
throw new IllegalArgumentException("A domain is required");
}
try {
final URL url = new URL(domain);
this.url = new URL(url, "/.well-known/jwks.json");
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid jwks uri", e);
}
}
private Map getJwks() throws SigningKeyNotFoundException {
try {
final InputStream inputStream = this.url.openStream();
final JsonFactory factory = new JsonFactory();
final JsonParser parser = factory.createParser(inputStream);
final TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy