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

io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you 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.vertx.rxjava.ext.auth.oauth2;

import rx.Observable;
import rx.Single;
import io.vertx.rx.java.RxHelper;
import io.vertx.rx.java.WriteStreamSubscriber;
import io.vertx.rx.java.SingleOnSubscribeAdapter;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;

/**
 * Factory interface for creating OAuth2 based {@link io.vertx.rxjava.ext.auth.authentication.AuthenticationProvider} instances.
 *
 * 

* NOTE: This class has been automatically generated from the {@link io.vertx.ext.auth.oauth2.OAuth2Auth original} non RX-ified interface using Vert.x codegen. */ @RxGen(io.vertx.ext.auth.oauth2.OAuth2Auth.class) public class OAuth2Auth extends io.vertx.rxjava.ext.auth.authentication.AuthenticationProvider { @Override public String toString() { return delegate.toString(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; OAuth2Auth that = (OAuth2Auth) o; return delegate.equals(that.delegate); } @Override public int hashCode() { return delegate.hashCode(); } public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new OAuth2Auth((io.vertx.ext.auth.oauth2.OAuth2Auth) obj), OAuth2Auth::getDelegate ); private final io.vertx.ext.auth.oauth2.OAuth2Auth delegate; public OAuth2Auth(io.vertx.ext.auth.oauth2.OAuth2Auth delegate) { super(delegate); this.delegate = delegate; } public OAuth2Auth(Object delegate) { super((io.vertx.ext.auth.oauth2.OAuth2Auth)delegate); this.delegate = (io.vertx.ext.auth.oauth2.OAuth2Auth)delegate; } public io.vertx.ext.auth.oauth2.OAuth2Auth getDelegate() { return delegate; } private static final TypeArg TYPE_ARG_0 = new TypeArg(o1 -> io.vertx.rxjava.ext.auth.User.newInstance((io.vertx.ext.auth.User)o1), o1 -> o1.getDelegate()); /** * Create a OAuth2 auth provider. * @param vertx the Vertx instance * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance((io.vertx.ext.auth.oauth2.OAuth2Auth)io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate())); return ret; } /** * Create a OAuth2 auth provider * @param vertx the Vertx instance * @param config the config * @return the auth provider */ public static io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth create(io.vertx.rxjava.core.Vertx vertx, io.vertx.ext.auth.oauth2.OAuth2Options config) { io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth ret = io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth.newInstance((io.vertx.ext.auth.oauth2.OAuth2Auth)io.vertx.ext.auth.oauth2.OAuth2Auth.create(vertx.getDelegate(), config)); return ret; } /** * Retrieve the public server JSON Web Key (JWK) required to verify the authenticity * of issued ID and access tokens. * @return Future result. */ public io.vertx.core.Future jWKSet() { io.vertx.core.Future ret = delegate.jWKSet().map(val -> val); return ret; } /** * Retrieve the public server JSON Web Key (JWK) required to verify the authenticity * of issued ID and access tokens. * @return Future result. */ public rx.Single rxJWKSet() { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { this.jWKSet().onComplete(fut); })); } /** * Handled to be called when a key (mentioned on a JWT) is missing from the current config. * Users are advised to call {@link io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth#jWKSet} but being careful to implement * some rate limiting function. *

* This method isn't generic for several reasons. The provider is not aware of the capabilities * of the backend IdP in terms of max allowed API calls. Some validation could be done at the * key id, which only the end user is aware of. *

* A base implementation for this handler is: * *

// are we already updating the jwks?
   private final AtomicBoolean updating = new AtomicBoolean(false);

   // default missing key handler, will try to reload with debounce
   oauth2.missingKeyHandler(keyId -> {
     if (updating.compareAndSet(false, true)) {
       // Refreshing JWKs due missing key
       jWKSet(done -> {
         updating.compareAndSet(true, false);
         if (done.failed()) {
           done.cause().printStackTrace();
   *       });
   *     }
   *   });
   * }
*

* This handler will purely debounce calls and allow only a single request to {@link io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth#jWKSet} * at a time. No special handling is done to avoid requests on wrong key ids or prevent to many * requests to the IdP server. Users should probably also account for the number of errors to * present DDoS the IdP. * @param handler * @return Future result. */ public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth missingKeyHandler(io.vertx.core.Handler handler) { delegate.missingKeyHandler(handler); return this; } /** * The client sends the end-user's browser to this endpoint to request their * authentication and consent. This endpoint is used in the code and implicit * OAuth 2.0 flows which require end-user interaction. * @param url Base URL with path together with other parameters to be included in the final URL. * @return the url to be used to authorize the user. */ public java.lang.String authorizeURL(io.vertx.ext.auth.oauth2.OAuth2AuthorizationURL url) { java.lang.String ret = delegate.authorizeURL(url); return ret; } /** * Refresh the current User (access token). * @param user the user (access token) to be refreshed. * @return future result */ public io.vertx.core.Future refresh(io.vertx.rxjava.ext.auth.User user) { io.vertx.core.Future ret = delegate.refresh(user.getDelegate()).map(val -> io.vertx.rxjava.ext.auth.User.newInstance((io.vertx.ext.auth.User)val)); return ret; } /** * Refresh the current User (access token). * @param user the user (access token) to be refreshed. * @return future result */ public rx.Single rxRefresh(io.vertx.rxjava.ext.auth.User user) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { this.refresh(user).onComplete(fut); })); } /** * Revoke an obtained access or refresh token. More info https://tools.ietf.org/html/rfc7009. * @param user the user (access token) to revoke. * @param tokenType the token type (either access_token or refresh_token). * @return future result */ public io.vertx.core.Future revoke(io.vertx.rxjava.ext.auth.User user, java.lang.String tokenType) { io.vertx.core.Future ret = delegate.revoke(user.getDelegate(), tokenType).map(val -> val); return ret; } /** * Revoke an obtained access or refresh token. More info https://tools.ietf.org/html/rfc7009. * @param user the user (access token) to revoke. * @param tokenType the token type (either access_token or refresh_token). * @return future result */ public rx.Single rxRevoke(io.vertx.rxjava.ext.auth.User user, java.lang.String tokenType) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { this.revoke(user, tokenType).onComplete(fut); })); } /** * Revoke an obtained access token. More info https://tools.ietf.org/html/rfc7009. * @param user the user (access token) to revoke. * @return future result */ public io.vertx.core.Future revoke(io.vertx.rxjava.ext.auth.User user) { io.vertx.core.Future ret = delegate.revoke(user.getDelegate()).map(val -> val); return ret; } /** * Revoke an obtained access token. More info https://tools.ietf.org/html/rfc7009. * @param user the user (access token) to revoke. * @return future result */ public rx.Single rxRevoke(io.vertx.rxjava.ext.auth.User user) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { this.revoke(user).onComplete(fut); })); } /** * Retrieve profile information and other attributes for a logged-in end-user. More info https://openid.net/specs/openid-connect-core-1_0.html#UserInfo * @param user the user (access token) to fetch the user info. * @return future result */ public io.vertx.core.Future userInfo(io.vertx.rxjava.ext.auth.User user) { io.vertx.core.Future ret = delegate.userInfo(user.getDelegate()).map(val -> val); return ret; } /** * Retrieve profile information and other attributes for a logged-in end-user. More info https://openid.net/specs/openid-connect-core-1_0.html#UserInfo * @param user the user (access token) to fetch the user info. * @return future result */ public rx.Single rxUserInfo(io.vertx.rxjava.ext.auth.User user) { return Single.create(new SingleOnSubscribeAdapter<>(fut -> { this.userInfo(user).onComplete(fut); })); } /** * The logout (end-session) endpoint is specified in OpenID Connect Session Management 1.0. * More info: https://openid.net/specs/openid-connect-session-1_0.html. * @param user the user to generate the url for * @param params extra parameters to apply to the url * @return the url to end the session. */ public java.lang.String endSessionURL(io.vertx.rxjava.ext.auth.User user, io.vertx.core.json.JsonObject params) { java.lang.String ret = delegate.endSessionURL(user.getDelegate(), params); return ret; } /** * The logout (end-session) endpoint is specified in OpenID Connect Session Management 1.0. * More info: https://openid.net/specs/openid-connect-session-1_0.html. * @param user the user to generate the url for * @return the url to end the session. */ public java.lang.String endSessionURL(io.vertx.rxjava.ext.auth.User user) { java.lang.String ret = delegate.endSessionURL(user.getDelegate()); return ret; } /** * Releases any resources or timers used by this instance. Users are expected to call this method when the provider * isn't needed any more to return the used resources back to the platform. */ public void close() { delegate.close(); } public static OAuth2Auth newInstance(io.vertx.ext.auth.oauth2.OAuth2Auth arg) { return arg != null ? new OAuth2Auth(arg) : null; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy