class Simple::OAuth2::Configuration

Simple::OAuth2 configuration class. Contains default or customized options that would be used in OAuth2 endpoints and helpers

Attributes

access_grant_class_name[RW]

The names of the classes that represents OAuth2 roles

@return [String] class name

access_token_class_name[RW]

The names of the classes that represents OAuth2 roles

@return [String] class name

access_token_lifetime[RW]

Access Token and Authorization Code lifetime in seconds

@return [Integer] lifetime in seconds

allowed_grant_types[RW]

OAuth2 grant types (flows) allowed to be processed

@return [Array<String>] grant types

allowed_response_types[RW]

OAuth2 response types (flows) allowed to be processed

@return [Array<String>] response types

authorization_code_lifetime[RW]

Access Token and Authorization Code lifetime in seconds

@return [Integer] lifetime in seconds

client_class_name[RW]

The names of the classes that represents OAuth2 roles

@return [String] class name

issue_refresh_token[RW]

Specifies whether to generate a Refresh Token when creating an Access Token

@return [Boolean] true if need to generate refresh token

on_refresh[RW]

Callback that would be invoked during processing of Refresh Token request for the original Access Token found by token value

realm[RW]

Realm value

@return [String] realm

resource_owner_authenticator[RW]

Resource Owner authenticator block option for customization

resource_owner_class_name[RW]

The names of the classes that represents OAuth2 roles

@return [String] class name

scopes_validator_class_name[RW]

Class name for the OAuth2 helper class that validates requested scopes against Access Token scopes

@return [String] scope validator class name

token_authenticator[RW]

Access Token authenticator block option for customization

token_generator_class_name[RW]

Class name for the OAuth2 helper class that generates unique token values

@return [String] token generator class name

Public Class Methods

new() click to toggle source

Return a new instance of Configuration with default options

# File lib/simple_oauth2/configuration.rb, line 69
def initialize
  setup!
end

Public Instance Methods

default_token_authenticator() click to toggle source

Default Access Token authenticator block. Validates token value passed with the request params

# File lib/simple_oauth2/configuration.rb, line 114
def default_token_authenticator
  lambda do |request|
    access_token_class.by_token(request.access_token) || request.invalid_token!
  end
end
on_refresh_runnable?() click to toggle source

Indicates if on_refresh callback can be invoked.

@return [Boolean]

true if callback can be invoked and false in other cases
# File lib/simple_oauth2/configuration.rb, line 98
def on_refresh_runnable?
  !on_refresh.nil? && on_refresh != :nothing
end

Private Instance Methods

default_resource_owner_authenticator() click to toggle source

Default Resource Owner authenticator block

# File lib/simple_oauth2/configuration.rb, line 139
def default_resource_owner_authenticator
  lambda do |_request|
    raise(
      'Resource Owner find failed due to '\
      'Simple::OAuth2.configure.resource_owner_authenticator being unconfigured.'
    )
  end
end
init_authenticators() click to toggle source

Sets authenticators to gem defaults

# File lib/simple_oauth2/configuration.rb, line 155
def init_authenticators
  self.token_authenticator = default_token_authenticator
  self.resource_owner_authenticator = default_resource_owner_authenticator
end
init_classes() click to toggle source

Sets OAuth2 helpers classes to gem defaults

# File lib/simple_oauth2/configuration.rb, line 149
def init_classes
  self.token_generator_class_name = Simple::OAuth2::UniqToken.name
  self.scopes_validator_class_name = Simple::OAuth2::Scopes.name
end
init_represents_roles() click to toggle source

Sets OAuth2 represents roles

# File lib/simple_oauth2/configuration.rb, line 161
def init_represents_roles
  self.access_token_class_name = DEFAULT_ACCESS_TOKEN_CLASS
  self.resource_owner_class_name = DEFAULT_RESOURCE_OWNER_CLASS
  self.client_class_name = DEFAULT_CLIENT_CLASS
  self.access_grant_class_name = DEFAULT_ACCESS_GRANT_CLASS
end
setup!() click to toggle source

Setup configuration to default options values

# File lib/simple_oauth2/configuration.rb, line 123
def setup!
  init_classes
  init_authenticators
  init_represents_roles

  self.access_token_lifetime = DEFAULT_TOKEN_LIFETIME
  self.authorization_code_lifetime = DEFAULT_CODE_LIFETIME
  self.allowed_grant_types = SUPPORTED_GRANT_TYPES
  self.allowed_response_types = SUPPORTED_RESPONSE_TYPES
  self.issue_refresh_token = DEFAULT_ISSUE_REFRESH_TOKEN
  self.on_refresh = :nothing

  self.realm = DEFAULT_REALM
end