fish.payara.microprofile.config.extensions.oauth.OAuth2Client Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payara-client Show documentation
Show all versions of payara-client Show documentation
Appclient for Payara Server
The newest version!
package fish.payara.microprofile.config.extensions.oauth;
import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.function.Supplier;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation.Builder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Form;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
/**
* A client for accessing an OAuth2 token endpoint. Synchronised for concurrent
* access, and supports keeping the same token active until it expires.
*
* @author Matthew Gill
*/
public class OAuth2Client {
private final Supplier invocation;
private Response lastResponse;
private volatile Instant lastResponseTime;
private volatile Duration expiryTime;
public OAuth2Client(String authUrl, String referrer, Map extends Serializable, ? extends Serializable> data) {
// Create the base target
final WebTarget target = ClientBuilder.newClient().target(authUrl);
// Create form data
final Form input = new Form();
data.forEach((key, value) -> input.param(key.toString(), value.toString()));
final Entity
© 2015 - 2024 Weber Informatics LLC | Privacy Policy