All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.trino.server.security.oauth2.OAuth2Client Maven / Gradle / Ivy

There is a newer version: 465
Show newest version
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.trino.server.security.oauth2;

import java.net.URI;
import java.time.Instant;
import java.util.Map;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

public interface OAuth2Client
{
    void load();

    Request createAuthorizationRequest(String state, URI callbackUri);

    Response getOAuth2Response(String code, URI callbackUri, Optional nonce)
            throws ChallengeFailedException;

    Optional> getClaims(String accessToken);

    Response refreshTokens(String refreshToken)
            throws ChallengeFailedException;

    Optional getLogoutEndpoint(Optional idToken, URI callbackUrl);

    class Request
    {
        private final URI authorizationUri;
        private final Optional nonce;

        public Request(URI authorizationUri, Optional nonce)
        {
            this.authorizationUri = requireNonNull(authorizationUri, "authorizationUri is null");
            this.nonce = requireNonNull(nonce, "nonce is null");
        }

        public URI getAuthorizationUri()
        {
            return authorizationUri;
        }

        public Optional getNonce()
        {
            return nonce;
        }
    }

    class Response
    {
        private final String accessToken;
        private final Instant expiration;
        private final Optional idToken;

        private final Optional refreshToken;

        public Response(String accessToken, Instant expiration, Optional idToken, Optional refreshToken)
        {
            this.accessToken = requireNonNull(accessToken, "accessToken is null");
            this.expiration = requireNonNull(expiration, "expiration is null");
            this.idToken = requireNonNull(idToken, "idToken is null");
            this.refreshToken = requireNonNull(refreshToken, "refreshToken is null");
        }

        public String getAccessToken()
        {
            return accessToken;
        }

        public Instant getExpiration()
        {
            return expiration;
        }

        public Optional getIdToken()
        {
            return idToken;
        }

        public Optional getRefreshToken()
        {
            return refreshToken;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy