io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth Maven / Gradle / Ivy
/*
 * 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.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;
  }
  /**
   * 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. The provider will refresh the keys according to:
   * https://openid.net/specs/openid-connect-core-1_0.html#RotateEncKeys
   *
   * This means that the provider will look at the cache headers and will refresh when
   * the max-age is reached. If the server does not return any cache headers it shall
   * be up to the end user to call this method to refresh.
   *
   * To avoid the refresh to happen too late, this means that they keys will be invalid,
   * if the {@link io.vertx.ext.auth.oauth2.OAuth2Options} {@link io.vertx.ext.auth.JWTOptions} config contains a
   * positive leeway, it will be used to request the refresh ahead of time.
   *
   * Key rotation can be controled by {@link io.vertx.ext.auth.oauth2.OAuth2Options}.
   * @param handler the handler success/failure.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth jWKSet(io.vertx.core.Handler> handler) { 
    delegate.jWKSet(handler);
    return this;
  }
  /**
   * Retrieve the public server JSON Web Key (JWK) required to verify the authenticity
   * of issued ID and access tokens. The provider will refresh the keys according to:
   * https://openid.net/specs/openid-connect-core-1_0.html#RotateEncKeys
   *
   * This means that the provider will look at the cache headers and will refresh when
   * the max-age is reached. If the server does not return any cache headers it shall
   * be up to the end user to call this method to refresh.
   *
   * To avoid the refresh to happen too late, this means that they keys will be invalid,
   * if the {@link io.vertx.ext.auth.oauth2.OAuth2Options} {@link io.vertx.ext.auth.JWTOptions} config contains a
   * positive leeway, it will be used to request the refresh ahead of time.
   *
   * Key rotation can be controled by {@link io.vertx.ext.auth.oauth2.OAuth2Options}.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth jWKSet() {
    return 
jWKSet(ar -> { });
  }
    /**
   * Retrieve the public server JSON Web Key (JWK) required to verify the authenticity
   * of issued ID and access tokens. The provider will refresh the keys according to:
   * https://openid.net/specs/openid-connect-core-1_0.html#RotateEncKeys
   *
   * This means that the provider will look at the cache headers and will refresh when
   * the max-age is reached. If the server does not return any cache headers it shall
   * be up to the end user to call this method to refresh.
   *
   * To avoid the refresh to happen too late, this means that they keys will be invalid,
   * if the {@link io.vertx.ext.auth.oauth2.OAuth2Options} {@link io.vertx.ext.auth.JWTOptions} config contains a
   * positive leeway, it will be used to request the refresh ahead of time.
   *
   * Key rotation can be controled by {@link io.vertx.ext.auth.oauth2.OAuth2Options}.
   * @return fluent self.
   */
  public rx.Single rxJWKSet() { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      jWKSet(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 params extra params to be included in the final URL.
   * @return the url to be used to authorize the user.
   */
  public java.lang.String authorizeURL(io.vertx.core.json.JsonObject params) { 
    java.lang.String ret = delegate.authorizeURL(params);
    return ret;
  }
  /**
   * Refresh the current User (access token).
   * @param user the user (access token) to be refreshed.
   * @param handler the handler success/failure.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth refresh(io.vertx.rxjava.ext.auth.User user, io.vertx.core.Handler> handler) { 
    delegate.refresh(user.getDelegate(), new Handler>() {
      public void handle(AsyncResult ar) {
        if (ar.succeeded()) {
          handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.auth.User.newInstance((io.vertx.ext.auth.User)ar.result())));
        } else {
          handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
        }
      }
    });
    return this;
  }
  /**
   * Refresh the current User (access token).
   * @param user the user (access token) to be refreshed.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth refresh(io.vertx.rxjava.ext.auth.User user) {
    return 
refresh(user, ar -> { });
  }
    /**
   * Refresh the current User (access token).
   * @param user the user (access token) to be refreshed.
   * @return fluent self.
   */
  public rx.Single rxRefresh(io.vertx.rxjava.ext.auth.User user) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      refresh(user, 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).
   * @param handler the handler success/failure.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth revoke(io.vertx.rxjava.ext.auth.User user, java.lang.String tokenType, io.vertx.core.Handler> handler) { 
    delegate.revoke(user.getDelegate(), tokenType, handler);
    return this;
  }
  /**
   * 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 fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth revoke(io.vertx.rxjava.ext.auth.User user, java.lang.String tokenType) {
    return 
revoke(user, tokenType, ar -> { });
  }
    /**
   * 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 fluent self.
   */
  public rx.Single rxRevoke(io.vertx.rxjava.ext.auth.User user, java.lang.String tokenType) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      revoke(user, tokenType, fut);
    }));
  }
  /**
   * Revoke an obtained access token. More info https://tools.ietf.org/html/rfc7009.
   * @param user the user (access token) to revoke.
   * @param handler the handler success/failure.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth revoke(io.vertx.rxjava.ext.auth.User user, io.vertx.core.Handler> handler) { 
    delegate.revoke(user.getDelegate(), handler);
    return this;
  }
  /**
   * Revoke an obtained access token. More info https://tools.ietf.org/html/rfc7009.
   * @param user the user (access token) to revoke.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth revoke(io.vertx.rxjava.ext.auth.User user) {
    return 
revoke(user, ar -> { });
  }
    /**
   * Revoke an obtained access token. More info https://tools.ietf.org/html/rfc7009.
   * @param user the user (access token) to revoke.
   * @return fluent self.
   */
  public rx.Single rxRevoke(io.vertx.rxjava.ext.auth.User user) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      revoke(user, 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.
   * @param handler the handler success/failure.
   * @return fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth userInfo(io.vertx.rxjava.ext.auth.User user, io.vertx.core.Handler> handler) { 
    delegate.userInfo(user.getDelegate(), handler);
    return this;
  }
  /**
   * 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 fluent self.
   */
  public io.vertx.rxjava.ext.auth.oauth2.OAuth2Auth userInfo(io.vertx.rxjava.ext.auth.User user) {
    return 
userInfo(user, ar -> { });
  }
    /**
   * 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 fluent self.
   */
  public rx.Single rxUserInfo(io.vertx.rxjava.ext.auth.User user) { 
    return Single.create(new SingleOnSubscribeAdapter<>(fut -> {
      userInfo(user, 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