Class: Grape::OAuth2::Configuration
- Inherits:
-
Object
- Object
- Grape::OAuth2::Configuration
- Includes:
- ClassAccessors, Validation
- Defined in:
- lib/grape_oauth2/configuration.rb,
lib/grape_oauth2/configuration/validation.rb
Overview
Grape::OAuth2 configuration class. Contains default or customized options that would be used in OAuth2 endpoints and helpers.
Defined Under Namespace
Modules: Validation
Constant Summary collapse
- Error =
Default Grape::OAuth2 configuration error class.
Class.new(StandardError)
- APIMissing =
Grape::OAuth2 configuration error for missing API required for OAuth2 classes.
Class.new(Error)
- DEFAULT_TOKEN_LIFETIME =
Default Access Token TTL (in seconds)
7200- DEFAULT_CODE_LIFETIME =
Default Authorization Code TTL ()in seconds)
1800- DEFAULT_REALM =
Default realm value
'OAuth 2.0'.freeze
- SUPPORTED_GRANT_TYPES =
Currently supported (be the gem) OAuth2 grant types
%w(password client_credentials refresh_token).freeze
Instance Attribute Summary collapse
-
#access_grant_class_name ⇒ String
The names of the classes that represents OAuth2 roles.
-
#access_token_class_name ⇒ String
The names of the classes that represents OAuth2 roles.
-
#access_token_lifetime ⇒ Object
Access Token and Authorization Code lifetime in seconds.
-
#allowed_grant_types ⇒ Array<String>
OAuth2 grant types (flows) allowed to be processed.
-
#authorization_code_lifetime ⇒ Object
Access Token and Authorization Code lifetime in seconds.
-
#client_class_name ⇒ String
The names of the classes that represents OAuth2 roles.
-
#issue_refresh_token ⇒ Boolean
Specifies whether to generate a Refresh Token when creating an Access Token.
-
#on_refresh(&block) ⇒ Object
Accessor for on_refresh callback.
-
#realm ⇒ String
Realm value.
-
#resource_owner_class_name ⇒ String
The names of the classes that represents OAuth2 roles.
-
#scopes_validator_class_name ⇒ String
Class name for the OAuth2 helper class that validates requested scopes against Access Token scopes.
-
#token_authenticator(&block) ⇒ Object
Accessor for Access Token authenticator block.
-
#token_generator_class_name ⇒ String
Class name for the OAuth2 helper class that generates unique token values.
Instance Method Summary collapse
-
#default_token_authenticator ⇒ Object
Default Access Token authenticator block.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#on_refresh_runnable? ⇒ Boolean
Indicates if on_refresh callback can be invoked.
-
#reset! ⇒ Object
Reset configuration to default options values.
Methods included from ClassAccessors
#access_grant_class, #access_token_class, #client_class, #resource_owner_class, #scopes_validator, #token_generator
Methods included from Validation
Constructor Details
#initialize ⇒ Configuration
73 74 75 |
# File 'lib/grape_oauth2/configuration.rb', line 73 def initialize reset! end |
Instance Attribute Details
#access_grant_class_name ⇒ String
The names of the classes that represents OAuth2 roles
30 31 32 |
# File 'lib/grape_oauth2/configuration.rb', line 30 def access_grant_class_name @access_grant_class_name end |
#access_token_class_name ⇒ String
The names of the classes that represents OAuth2 roles
30 31 32 |
# File 'lib/grape_oauth2/configuration.rb', line 30 def access_token_class_name @access_token_class_name end |
#access_token_lifetime ⇒ Object
Access Token and Authorization Code lifetime in seconds
52 53 54 |
# File 'lib/grape_oauth2/configuration.rb', line 52 def access_token_lifetime @access_token_lifetime end |
#allowed_grant_types ⇒ Array<String>
OAuth2 grant types (flows) allowed to be processed
49 50 51 |
# File 'lib/grape_oauth2/configuration.rb', line 49 def allowed_grant_types @allowed_grant_types end |
#authorization_code_lifetime ⇒ Object
Access Token and Authorization Code lifetime in seconds
52 53 54 |
# File 'lib/grape_oauth2/configuration.rb', line 52 def end |
#client_class_name ⇒ String
The names of the classes that represents OAuth2 roles
30 31 32 |
# File 'lib/grape_oauth2/configuration.rb', line 30 def client_class_name @client_class_name end |
#issue_refresh_token ⇒ Boolean
Specifies whether to generate a Refresh Token when creating an Access Token
58 59 60 |
# File 'lib/grape_oauth2/configuration.rb', line 58 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.
71 72 73 |
# File 'lib/grape_oauth2/configuration.rb', line 71 def on_refresh @on_refresh end |
#realm ⇒ String
Realm value
64 65 66 |
# File 'lib/grape_oauth2/configuration.rb', line 64 def realm @realm end |
#resource_owner_class_name ⇒ String
The names of the classes that represents OAuth2 roles
30 31 32 |
# File 'lib/grape_oauth2/configuration.rb', line 30 def resource_owner_class_name @resource_owner_class_name end |
#scopes_validator_class_name ⇒ String
Class name for the OAuth2 helper class that validates requested scopes against Access Token scopes
37 38 39 |
# File 'lib/grape_oauth2/configuration.rb', line 37 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.
67 68 69 |
# File 'lib/grape_oauth2/configuration.rb', line 67 def token_authenticator @token_authenticator end |
#token_generator_class_name ⇒ String
Class name for the OAuth2 helper class that generates unique token values
43 44 45 |
# File 'lib/grape_oauth2/configuration.rb', line 43 def token_generator_class_name @token_generator_class_name end |
Instance Method Details
#default_token_authenticator ⇒ Object
Default Access Token authenticator block. Validates token value passed with the request params.
79 80 81 82 83 |
# 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? ⇒ Boolean
Indicates if on_refresh callback can be invoked.
110 111 112 |
# File 'lib/grape_oauth2/configuration.rb', line 110 def on_refresh_runnable? !on_refresh.nil? && on_refresh != :nothing end |
#reset! ⇒ Object
Reset configuration to default options values.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/grape_oauth2/configuration.rb', line 115 def reset! initialize_classes initialize_authenticators self.access_token_lifetime = DEFAULT_TOKEN_LIFETIME self. = 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 |