Class List Method List File List

# Class: VertxAuthOauth2::OAuth2Auth

Inherits:
  VertxAuthCommon::AuthProvider
  - Object
  - VertxAuthCommon::AuthProvider
  - VertxAuthOauth2::OAuth2Auth
  show all
Defined in:
  /Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb

## Overview

Factory interface for creating OAuth2 based VertxAuthCommon::AuthProvider instances.

## Class Method Summary (collapse)

- + (::VertxAuthOauth2::OAuth2Auth) create(vertx = nil, flow = nil, config = nil)
  Create a OAuth2 auth provider.
- + (::VertxAuthOauth2::OAuth2Auth) create_keycloak(vertx = nil, flow = nil, config = nil)
  Create a OAuth2 auth provider.

## Instance Method Summary (collapse)

- - (self) api(method = nil, path = nil, params = nil) { ... }
  Call OAuth2 APIs.
- - (String) authorize_url(params = nil)
  Generate a redirect URL to the authN/Z backend.
- - (void) get_token(params = nil) { ... }
  Returns the Access Token object.
- - (true, false) has_jwt_token?
  Returns true if this provider supports JWT tokens as the access_token.

### Methods inherited from VertxAuthCommon::AuthProvider

#authenticate

## Class Method Details

### + (`::VertxAuthOauth2::OAuth2Auth`) create(vertx = nil, flow = nil, config = nil)

Create a OAuth2 auth provider

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the Vertx instance
- flow (`:AUTH_CODE`, `:CLIENT`, `:PASSWORD`) (defaults to: `nil`)
- config (`Hash`) (defaults to: `nil`) —
  the config

Returns:

- (`::VertxAuthOauth2::OAuth2Auth`) —
  the auth provider

Raises:

- (`ArgumentError`)

    36
    37
    38
    39
    40
    41
    42
    43
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 36

    def self.create(vertx=nil,flow=nil,config=nil)
      if vertx.class.method_defined?(:j_del) && flow.class == Symbol && !block_given? && config == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuthOauth2::OAuth2Auth.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtAuthOauth2::OAuth2FlowType.java_class]).call(vertx.j_del,Java::IoVertxExtAuthOauth2::OAuth2FlowType.valueOf(flow)),::VertxAuthOauth2::OAuth2Auth)
      elsif vertx.class.method_defined?(:j_del) && flow.class == Symbol && config.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuthOauth2::OAuth2Auth.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtAuthOauth2::OAuth2FlowType.java_class,Java::IoVertxExtAuthOauth2::OAuth2ClientOptions.java_class]).call(vertx.j_del,Java::IoVertxExtAuthOauth2::OAuth2FlowType.valueOf(flow),Java::IoVertxExtAuthOauth2::OAuth2ClientOptions.new(::Vertx::Util::Utils.to_json_object(config))),::VertxAuthOauth2::OAuth2Auth)
      end
      raise ArgumentError, "Invalid arguments when calling create(vertx,flow,config)"
    end

### + (`::VertxAuthOauth2::OAuth2Auth`) create_keycloak(vertx = nil, flow = nil, config = nil)

Create a OAuth2 auth provider

Parameters:

- vertx (`::Vertx::Vertx`) (defaults to: `nil`) —
  the Vertx instance
- flow (`:AUTH_CODE`, `:CLIENT`, `:PASSWORD`) (defaults to: `nil`)
- config (`Hash{String => Object}`) (defaults to: `nil`) —
  the config as exported from the admin console

Returns:

- (`::VertxAuthOauth2::OAuth2Auth`) —
  the auth provider

Raises:

- (`ArgumentError`)

    25
    26
    27
    28
    29
    30
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 25

    def self.create_keycloak(vertx=nil,flow=nil,config=nil)
      if vertx.class.method_defined?(:j_del) && flow.class == Symbol && config.class == Hash && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtAuthOauth2::OAuth2Auth.java_method(:createKeycloak, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxExtAuthOauth2::OAuth2FlowType.java_class,Java::IoVertxCoreJson::JsonObject.java_class]).call(vertx.j_del,Java::IoVertxExtAuthOauth2::OAuth2FlowType.valueOf(flow),::Vertx::Util::Utils.to_json_object(config)),::VertxAuthOauth2::OAuth2Auth)
      end
      raise ArgumentError, "Invalid arguments when calling create_keycloak(vertx,flow,config)"
    end

## Instance Method Details

### - (`self`) api(method = nil, path = nil, params = nil) { ... }

Call OAuth2 APIs.

Parameters:

- method (`:OPTIONS`, `:GET`, `:HEAD`, `:POST`, `:PUT`, `:DELETE`, `:TRACE`, `:CONNECT`, `:PATCH`, `:OTHER`) (defaults to: `nil`) —
  HttpMethod
- path (`String`) (defaults to: `nil`) —
  target path
- params (`Hash{String => Object}`) (defaults to: `nil`) —
  parameters

Yields:

- handler

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    69
    70
    71
    72
    73
    74
    75
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 69

    def api(method=nil,path=nil,params=nil)
      if method.class == Symbol && path.class == String && params.class == Hash && block_given?
        @j_del.java_method(:api, [Java::IoVertxCoreHttp::HttpMethod.java_class,Java::java.lang.String.java_class,Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(Java::IoVertxCoreHttp::HttpMethod.valueOf(method),path,::Vertx::Util::Utils.to_json_object(params),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.encode) : nil : nil) }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling api(method,path,params)"
    end

### - (`String`) authorize_url(params = nil)

Generate a redirect URL to the authN/Z backend. It only applies to auth_code flow.

Parameters:

- params (`Hash{String => Object}`) (defaults to: `nil`)

Returns:

- (`String`)

Raises:

- (`ArgumentError`)

    47
    48
    49
    50
    51
    52
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 47

    def authorize_url(params=nil)
      if params.class == Hash && !block_given?
        return @j_del.java_method(:authorizeURL, [Java::IoVertxCoreJson::JsonObject.java_class]).call(::Vertx::Util::Utils.to_json_object(params))
      end
      raise ArgumentError, "Invalid arguments when calling authorize_url(params)"
    end

### - (`void`) get_token(params = nil) { ... }

This method returns an undefined value.

Returns the Access Token object.

Parameters:

- params (`Hash{String => Object}`) (defaults to: `nil`) —
  - JSON with the options, each flow requires different options.

Yields:

- - The handler returning the results.

Raises:

- (`ArgumentError`)

    57
    58
    59
    60
    61
    62
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 57

    def get_token(params=nil)
      if params.class == Hash && block_given?
        return @j_del.java_method(:getToken, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(params),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxAuthOauth2::AccessToken) : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling get_token(params)"
    end

### - (`true`, `false`) has_jwt_token?

Returns true if this provider supports JWT tokens as the access_token. This is typically true if the provider implements the `openid-connect` protocol. This is a plain return from the config option jwtToken, which is false by default. This information is important to validate grants. Since pure OAuth2 should be used for authorization and when a token is requested all grants should be declared, in case of openid-connect this is not true. OpenId will issue a token and all grants will be encoded on the token itself so the requester does not need to list the required grants.

Returns:

- (`true`, `false`) —
  true if openid-connect is used.

Raises:

- (`ArgumentError`)

    85
    86
    87
    88
    89
    90
    # File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-auth-oauth2/o_auth2_auth.rb', line 85

    def has_jwt_token?
      if !block_given?
        return @j_del.java_method(:hasJWTToken, []).call()
      end
      raise ArgumentError, "Invalid arguments when calling has_jwt_token?()"
    end