Class: Moguera::Authentication
- Inherits:
-
Object
- Object
- Moguera::Authentication
- Defined in:
- lib/moguera/authentication.rb,
lib/moguera/authentication/request.rb,
lib/moguera/authentication/version.rb,
lib/moguera/authentication/exception.rb
Defined Under Namespace
Classes: AuthenticationError, BlockRequired, ParameterInvalid, Request, RequestTokenRequired, UserNotFound
Constant Summary collapse
- VERSION =
"0.2.1"
Instance Attribute Summary collapse
-
#allow_time_interval ⇒ Object
Returns the value of attribute allow_time_interval.
Instance Method Summary collapse
- #authenticate(&block) ⇒ Object
- #authenticate!(&block) ⇒ Object
-
#initialize(request_token = nil) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(request_token = nil) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 13 14 |
# File 'lib/moguera/authentication.rb', line 9 def initialize(request_token = nil) raise RequestTokenRequired, 'Missing request token.' unless request_token @request_token = request_token @allow_time_interval = allow_time_interval || 600 end |
Instance Attribute Details
#allow_time_interval ⇒ Object
Returns the value of attribute allow_time_interval.
7 8 9 |
# File 'lib/moguera/authentication.rb', line 7 def allow_time_interval @allow_time_interval end |
Instance Method Details
#authenticate(&block) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/moguera/authentication.rb', line 33 def authenticate(&block) authenticate!(&block) rescue AuthenticationError false end |
#authenticate!(&block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/moguera/authentication.rb', line 16 def authenticate!(&block) raise BlockRequired, 'Request token required.' unless block_given? access_key = extract_access_key_from_token(token: @request_token) server_request = block.call(access_key) validate_token!(server_token: server_request.token, request_token: @request_token) validate_time!(request_time: server_request.http_date) server_request rescue AuthenticationError => e authentication_error = AuthenticationError.new(e.) authentication_error.request_token = @request_token authentication_error.server_request = server_request if server_request raise authentication_error end |