class Grape::OAuth2::Configuration

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

Constants

APIMissing

Grape::OAuth2 configuration error for missing API required for OAuth2 classes.

DEFAULT_CODE_LIFETIME

Default Authorization Code TTL ()in seconds)

DEFAULT_REALM

Default realm value

DEFAULT_TOKEN_LIFETIME

Default Access Token TTL (in seconds)

Error

Default Grape::OAuth2 configuration error class.

SUPPORTED_GRANT_TYPES

Currently supported (by the gem) OAuth2 grant types

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

allowed_grant_types[RW]
OAuth2 grant types (flows) allowed to be processed

@return [Array<String>] grant types

authorization_code_lifetime[RW]

Access Token and Authorization Code 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, false in other case

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_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] scopes 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
# File lib/grape_oauth2/configuration.rb, line 73
def initialize
  reset!
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/grape_oauth2/configuration.rb, line 79
def default_token_authenticator
  lambda do |request|
    access_token_class.authenticate(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/grape_oauth2/configuration.rb, line 110
def on_refresh_runnable?
  !on_refresh.nil? && on_refresh != :nothing
end
reset!() click to toggle source

Reset configuration to default options values.

# File lib/grape_oauth2/configuration.rb, line 115
def reset!
  initialize_classes
  initialize_authenticators

  self.access_token_lifetime = DEFAULT_TOKEN_LIFETIME
  self.authorization_code_lifetime = DEFAULT_CODE_LIFETIME
  self.allowed_grant_types = %w[password client_credentials]

  self.issue_refresh_token = false
  self.on_refresh = :nothing

  self.realm = DEFAULT_REALM
end

Private Instance Methods

initialize_authenticators() click to toggle source

Sets authenticators to gem defaults.

# File lib/grape_oauth2/configuration.rb, line 138
def initialize_authenticators
  self.token_authenticator = default_token_authenticator
end
initialize_classes() click to toggle source

Sets OAuth2 helpers classes to gem defaults.

# File lib/grape_oauth2/configuration.rb, line 132
def initialize_classes
  self.scopes_validator_class_name = Grape::OAuth2::Scopes.name
  self.token_generator_class_name = Grape::OAuth2::UniqueToken.name
end