Class: Simple::OAuth2::Configuration

Inherits:
Object
  • Object
show all
Includes:
ClassAccessors, Constants
Defined in:
lib/simple_oauth2/configuration.rb

Overview

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

Constant Summary

Constants included from Constants

Simple::OAuth2::Constants::DEFAULT_ACCESS_GRANT_CLASS, Simple::OAuth2::Constants::DEFAULT_ACCESS_TOKEN_CLASS, Simple::OAuth2::Constants::DEFAULT_CLIENT_CLASS, Simple::OAuth2::Constants::DEFAULT_CODE_LIFETIME, Simple::OAuth2::Constants::DEFAULT_ISSUE_REFRESH_TOKEN, Simple::OAuth2::Constants::DEFAULT_REALM, Simple::OAuth2::Constants::DEFAULT_RESOURCE_OWNER_CLASS, Simple::OAuth2::Constants::DEFAULT_TOKEN_LIFETIME, Simple::OAuth2::Constants::SUPPORTED_GRANT_TYPES, Simple::OAuth2::Constants::SUPPORTED_RESPONSE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassAccessors

#access_grant_class, #access_token_class, #client_class, #resource_owner_class, #scopes_validator, #token_generator

Constructor Details

#initializeConfiguration

Return a new instance of Configuration with default options



69
70
71
# File 'lib/simple_oauth2/configuration.rb', line 69

def initialize
  setup!
end

Instance Attribute Details

#access_grant_class_nameString

The names of the classes that represents OAuth2 roles

Returns:

  • (String)

    class name



13
14
15
# File 'lib/simple_oauth2/configuration.rb', line 13

def access_grant_class_name
  @access_grant_class_name
end

#access_token_class_nameString

The names of the classes that represents OAuth2 roles

Returns:

  • (String)

    class name



13
14
15
# File 'lib/simple_oauth2/configuration.rb', line 13

def access_token_class_name
  @access_token_class_name
end

#access_token_lifetimeInteger

Access Token and Authorization Code lifetime in seconds

Returns:

  • (Integer)

    lifetime in seconds



32
33
34
# File 'lib/simple_oauth2/configuration.rb', line 32

def access_token_lifetime
  @access_token_lifetime
end

#allowed_grant_typesArray<String>

OAuth2 grant types (flows) allowed to be processed

Returns:

  • (Array<String>)

    grant types



38
39
40
# File 'lib/simple_oauth2/configuration.rb', line 38

def allowed_grant_types
  @allowed_grant_types
end

#allowed_response_typesArray<String>

OAuth2 response types (flows) allowed to be processed

Returns:

  • (Array<String>)

    response types



44
45
46
# File 'lib/simple_oauth2/configuration.rb', line 44

def allowed_response_types
  @allowed_response_types
end

#authorization_code_lifetimeInteger

Access Token and Authorization Code lifetime in seconds

Returns:

  • (Integer)

    lifetime in seconds



32
33
34
# File 'lib/simple_oauth2/configuration.rb', line 32

def authorization_code_lifetime
  @authorization_code_lifetime
end

#client_class_nameString

The names of the classes that represents OAuth2 roles

Returns:

  • (String)

    class name



13
14
15
# File 'lib/simple_oauth2/configuration.rb', line 13

def client_class_name
  @client_class_name
end

#issue_refresh_tokenBoolean

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

Returns:

  • (Boolean)

    true if need to generate refresh token



62
63
64
# File 'lib/simple_oauth2/configuration.rb', line 62

def issue_refresh_token
  @issue_refresh_token
end

#on_refresh(&block) ⇒ Object

Accessor for on_refresh callback. Set callback proc if called with block or returns current value of the accessor.



66
67
68
# File 'lib/simple_oauth2/configuration.rb', line 66

def on_refresh
  @on_refresh
end

#realmString

Realm value

Returns:

  • (String)

    realm



50
51
52
# File 'lib/simple_oauth2/configuration.rb', line 50

def realm
  @realm
end

#resource_owner_authenticator(&block) ⇒ Object

Accessor for Resource Owner authenticator block. Set it to proc if called with block or returns current value of the accessor.



56
57
58
# File 'lib/simple_oauth2/configuration.rb', line 56

def resource_owner_authenticator
  @resource_owner_authenticator
end

#resource_owner_class_nameString

The names of the classes that represents OAuth2 roles

Returns:

  • (String)

    class name



13
14
15
# File 'lib/simple_oauth2/configuration.rb', line 13

def resource_owner_class_name
  @resource_owner_class_name
end

#scopes_validator_class_nameString

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

Returns:

  • (String)

    scope validator class name



26
27
28
# File 'lib/simple_oauth2/configuration.rb', line 26

def scopes_validator_class_name
  @scopes_validator_class_name
end

#token_authenticator(&block) ⇒ Object

Accessor for Access Token authenticator block. Set it to proc if called with block or returns current value of the accessor.



53
54
55
# File 'lib/simple_oauth2/configuration.rb', line 53

def token_authenticator
  @token_authenticator
end

#token_generator_class_nameString

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

Returns:

  • (String)

    token generator class name



20
21
22
# File 'lib/simple_oauth2/configuration.rb', line 20

def token_generator_class_name
  @token_generator_class_name
end

Instance Method Details

#default_token_authenticatorObject

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



114
115
116
117
118
# 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?Boolean

Indicates if on_refresh callback can be invoked.

Returns:

  • (Boolean)

    true if callback can be invoked and false in other cases



98
99
100
# File 'lib/simple_oauth2/configuration.rb', line 98

def on_refresh_runnable?
  !on_refresh.nil? && on_refresh != :nothing
end