Class: Rack::OAuth2::Client
- Inherits:
-
Object
- Object
- Rack::OAuth2::Client
- Includes:
- AttrOptional, AttrRequired
- Defined in:
- lib/rack/oauth2/client.rb,
lib/rack/oauth2/client/error.rb,
lib/rack/oauth2/client/grant.rb,
lib/rack/oauth2/client/grant/password.rb,
lib/rack/oauth2/client/grant/refresh_token.rb,
lib/rack/oauth2/client/grant/authorization_code.rb,
lib/rack/oauth2/client/grant/client_credentials.rb
Defined Under Namespace
Instance Method Summary collapse
- #access_token!(*args) ⇒ Object
- #authorization_code=(code) ⇒ Object
- #authorization_uri(params = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Client
constructor
A new instance of Client.
- #refresh_token=(token) ⇒ Object
- #resource_owner_credentials=(credentials) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 |
# File 'lib/rack/oauth2/client.rb', line 8 def initialize(attributes = {}) (required_attributes + optional_attributes).each do |key| self.send :"#{key}=", attributes[key] end @grant = Grant::ClientCredentials.new @authorization_endpoint ||= '/oauth2/authorize' @token_endpoint ||= '/oauth2/token' attr_missing! end |
Instance Method Details
#access_token!(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rack/oauth2/client.rb', line 48 def access_token!(*args) headers, params = {}, @grant.as_json # NOTE: # Using Array#estract_options! for backward compatibility. # Until v1.0.5, the first argument was 'client_auth_method' in scalar. = args. client_auth_method = args.first || [:client_auth_method] || :basic params[:scope] = Array([:scope]).join(' ') if [:scope].present? if secret && client_auth_method == :basic cred = ["#{identifier}:#{secret}"].pack('m').tr("\n", '') headers.merge!( 'Authorization' => "Basic #{cred}" ) else params.merge!( :client_id => identifier, :client_secret => secret ) end handle_response do Rack::OAuth2.http_client.post( absolute_uri_for(token_endpoint), Util.compact_hash(params), headers ) end end |
#authorization_code=(code) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rack/oauth2/client.rb', line 28 def (code) @grant = Grant::AuthorizationCode.new( :code => code, :redirect_uri => self.redirect_uri ) end |
#authorization_uri(params = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/oauth2/client.rb', line 18 def (params = {}) params[:response_type] ||= :code params[:response_type] = Array(params[:response_type]).join(' ') params[:scope] = Array(params[:scope]).join(' ') Util.redirect_uri absolute_uri_for(), :query, params.merge( :client_id => self.identifier, :redirect_uri => self.redirect_uri ) end |
#refresh_token=(token) ⇒ Object
42 43 44 45 46 |
# File 'lib/rack/oauth2/client.rb', line 42 def refresh_token=(token) @grant = Grant::RefreshToken.new( :refresh_token => token ) end |