Class: OAuth2c::ThreeLegged::Base
- Inherits:
-
Object
- Object
- OAuth2c::ThreeLegged::Base
- Defined in:
- lib/oauth2c/three_legged.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #authz_url ⇒ Object
-
#initialize(agent, state:, scope: []) ⇒ Base
constructor
A new instance of Base.
- #token(callback_url_or_params, fragment_params = nil) ⇒ Object
- #update_scope(scope) ⇒ Object
Constructor Details
#initialize(agent, state:, scope: []) ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 |
# File 'lib/oauth2c/three_legged.rb', line 24 def initialize(agent, state:, scope: []) @agent = agent @state = state update_scope(scope) end |
Instance Attribute Details
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
22 23 24 |
# File 'lib/oauth2c/three_legged.rb', line 22 def scope @scope end |
Instance Method Details
#authz_url ⇒ Object
34 35 36 |
# File 'lib/oauth2c/three_legged.rb', line 34 def authz_url @agent.authz_url(state: @state, scope: @scope, **authz_params) end |
#token(callback_url_or_params, fragment_params = nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/oauth2c/three_legged.rb', line 38 def token(callback_url_or_params, fragment_params = nil) case callback_url_or_params when String query_params, fragment_params = parse_callback_url(callback_url_or_params) when Hash query_params, fragment_params = callback_url_or_params, fragment_params else raise ArgumentError, "invalid arguments, expects URL or hash with params" end if query_params[:error] raise Error.new(query_params[:error], query_params[:error_description]) end if query_params[:state] != @state raise InvalidStateError, "callback url state mismatch" end if block_given? yield(query_params, fragment_params) else ok, response = @agent.token(include_redirect_uri: true, **token_params(query_params)) handle_token_response(ok, response) end end |
#update_scope(scope) ⇒ Object
30 31 32 |
# File 'lib/oauth2c/three_legged.rb', line 30 def update_scope(scope) @scope = scope.dup.freeze end |