Class List Method List File List

# Class: VertxWeb::OAuth2AuthHandler

Inherits:
  Object
  - Object
  - VertxWeb::OAuth2AuthHandler
  show all
Includes:
  AuthHandler
Defined in:
  /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb

## Overview

An auth handler that provides OAuth2 Authentication support. This handler is suitable for AuthCode flows.

## Constant Summary

@@j_api_type =

      Object.new

## Class Method Summary (collapse)

- + (Boolean) accept?(obj)
- + (::VertxWeb::OAuth2AuthHandler) create(authProvider = nil, callbackURL = nil)
  Create a OAuth2 auth handler with host pinning.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)

## Instance Method Summary (collapse)

- - (self) add_authorities(authorities = nil)
  Add a set of required authorities for this auth handler.
- - (self) add_authority(authority = nil)
  Add a required authority for this auth handler.
- - (void) authorize(user = nil) { ... }
  Authorizes the given user against all added authorities.
- - (self) extra_params(extraParams = nil)
  Extra parameters needed to be passed while requesting a token.
- - (void) handle(event = nil)
  Something has happened, so handle it.
- - (void) parse_credentials(context = nil) { ... }
  Parses the credentials from the request into a JsonObject.
- - (self) setup_callback(route = nil)
  add the callback handler to a given route.

## Class Method Details

### + (`Boolean`) accept?(obj)

Returns:

- (`Boolean`)

    23
    24
    25
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 23

    def @@j_api_type.accept?(obj)
      obj.class == OAuth2AuthHandler
    end

### + (`::VertxWeb::OAuth2AuthHandler`) create(authProvider = nil, callbackURL = nil)

Create a OAuth2 auth handler with host pinning

Parameters:

- authProvider (`::VertxAuthOauth2::OAuth2Auth`) (defaults to: `nil`) —
  the auth provider to use
- callbackURL (`String`) (defaults to: `nil`) —
  the callback URL you entered in your provider admin console, usually it should be something like: `https://myserver:8888/callback`

Returns:

- (`::VertxWeb::OAuth2AuthHandler`) —
  the auth handler

Raises:

- (`ArgumentError`)

    93
    94
    95
    96
    97
    98
    99
    100
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 93

    def self.create(authProvider=nil,callbackURL=nil)
      if authProvider.class.method_defined?(:j_del) && !block_given? && callbackURL == nil
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::OAuth2AuthHandler.java_method(:create, [Java::IoVertxExtAuthOauth2::OAuth2Auth.java_class]).call(authProvider.j_del),::VertxWeb::OAuth2AuthHandler)
      elsif authProvider.class.method_defined?(:j_del) && callbackURL.class == String && !block_given?
        return ::Vertx::Util::Utils.safe_create(Java::IoVertxExtWebHandler::OAuth2AuthHandler.java_method(:create, [Java::IoVertxExtAuthOauth2::OAuth2Auth.java_class,Java::java.lang.String.java_class]).call(authProvider.j_del,callbackURL),::VertxWeb::OAuth2AuthHandler)
      end
      raise ArgumentError, "Invalid arguments when calling create(#{authProvider},#{callbackURL})"
    end

### + (`Object`) j_api_type

    32
    33
    34
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 32

    def self.j_api_type
      @@j_api_type
    end

### + (`Object`) j_class

    35
    36
    37
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 35

    def self.j_class
      Java::IoVertxExtWebHandler::OAuth2AuthHandler.java_class
    end

### + (`Object`) unwrap(obj)

    29
    30
    31
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 29

    def @@j_api_type.unwrap(obj)
      obj.j_del
    end

### + (`Object`) wrap(obj)

    26
    27
    28
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 26

    def @@j_api_type.wrap(obj)
      OAuth2AuthHandler.new(obj)
    end

## Instance Method Details

### - (`self`) add_authorities(authorities = nil)

Add a set of required authorities for this auth handler

Parameters:

- authorities (`Set<String>`) (defaults to: `nil`) —
  the set of authorities

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    60
    61
    62
    63
    64
    65
    66
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 60

    def add_authorities(authorities=nil)
      if authorities.class == Set && !block_given?
        @j_del.java_method(:addAuthorities, [Java::JavaUtil::Set.java_class]).call(Java::JavaUtil::LinkedHashSet.new(authorities.map { |element| element }))
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_authorities(#{authorities})"
    end

### - (`self`) add_authority(authority = nil)

Add a required authority for this auth handler

Parameters:

- authority (`String`) (defaults to: `nil`) —
  the authority

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    50
    51
    52
    53
    54
    55
    56
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 50

    def add_authority(authority=nil)
      if authority.class == String && !block_given?
        @j_del.java_method(:addAuthority, [Java::java.lang.String.java_class]).call(authority)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling add_authority(#{authority})"
    end

### - (`void`) authorize(user = nil) { ... }

This method returns an undefined value.

Authorizes the given user against all added authorities.

Parameters:

- user (`::VertxAuthCommon::User`) (defaults to: `nil`) —
  a user.

Yields:

- the handler for the result.

Raises:

- (`ArgumentError`)

    83
    84
    85
    86
    87
    88
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 83

    def authorize(user=nil)
      if user.class.method_defined?(:j_del) && block_given?
        return @j_del.java_method(:authorize, [Java::IoVertxExtAuth::User.java_class,Java::IoVertxCore::Handler.java_class]).call(user.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling authorize(#{user})"
    end

### - (`self`) extra_params(extraParams = nil)

Extra parameters needed to be passed while requesting a token.

Parameters:

- extraParams (`Hash{String => Object}`) (defaults to: `nil`) —
  extra optional parameters.

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    104
    105
    106
    107
    108
    109
    110
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 104

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

### - (`void`) handle(event = nil)

This method returns an undefined value.

Something has happened, so handle it.

Parameters:

- event (`::VertxWeb::RoutingContext`) (defaults to: `nil`) —
  the event to handle

Raises:

- (`ArgumentError`)

    41
    42
    43
    44
    45
    46
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 41

    def handle(event=nil)
      if event.class.method_defined?(:j_del) && !block_given?
        return @j_del.java_method(:handle, [Java::IoVertxExtWeb::RoutingContext.java_class]).call(event.j_del)
      end
      raise ArgumentError, "Invalid arguments when calling handle(#{event})"
    end

### - (`void`) parse_credentials(context = nil) { ... }

This method returns an undefined value.

Parses the credentials from the request into a JsonObject. The implementation should be able to extract the required info for the auth provider in the format the provider expects.

Parameters:

- context (`::VertxWeb::RoutingContext`) (defaults to: `nil`) —
  the routing context

Yields:

- the handler to be called once the information is available.

Raises:

- (`ArgumentError`)

    73
    74
    75
    76
    77
    78
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 73

    def parse_credentials(context=nil)
      if context.class.method_defined?(:j_del) && block_given?
        return @j_del.java_method(:parseCredentials, [Java::IoVertxExtWeb::RoutingContext.java_class,Java::IoVertxCore::Handler.java_class]).call(context.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.encode) : nil : nil) }))
      end
      raise ArgumentError, "Invalid arguments when calling parse_credentials(#{context})"
    end

### - (`self`) setup_callback(route = nil)

add the callback handler to a given route.

Parameters:

- route (`::VertxWeb::Route`) (defaults to: `nil`) —
  a given route e.g.: `/callback`

Returns:

- (`self`)

Raises:

- (`ArgumentError`)

    114
    115
    116
    117
    118
    119
    120
    # File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-web/o_auth2_auth_handler.rb', line 114

    def setup_callback(route=nil)
      if route.class.method_defined?(:j_del) && !block_given?
        @j_del.java_method(:setupCallback, [Java::IoVertxExtWeb::Route.java_class]).call(route.j_del)
        return self
      end
      raise ArgumentError, "Invalid arguments when calling setup_callback(#{route})"
    end