Class: OAuth2::Client
- Inherits:
-
Object
- Object
- OAuth2::Client
- Defined in:
- lib/oauth2/client.rb
Constant Summary collapse
- DEFAULTS_PATHS =
{ :authorize_path => '/oauth2/authorize', :token_path => '/oauth2/token', :device_path => '/oauth2/device/code', }
Instance Attribute Summary collapse
-
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#connection_client ⇒ Object
Returns the value of attribute connection_client.
-
#connection_options ⇒ Object
Returns the value of attribute connection_options.
-
#device_path ⇒ Object
Returns the value of attribute device_path.
-
#host ⇒ Object
Returns the value of attribute host.
-
#token_path ⇒ Object
Returns the value of attribute token_path.
Instance Method Summary collapse
- #authorization_code ⇒ Object
- #client_credentials ⇒ Object
- #connection ⇒ Object
- #device_code ⇒ Object
- #implicit ⇒ Object
-
#initialize(host, client_id, client_secret, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#normalize_scope(scope, sep = ' ') ⇒ Object
Token scope definitions vary by service e.g Google uses space delimited scopes, while Github uses comma seperated scopes.
- #password ⇒ Object
- #refresh_token ⇒ Object
Constructor Details
#initialize(host, client_id, client_secret, options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/oauth2/client.rb', line 14 def initialize(host, client_id, client_secret, ={}) @host = host @client_id = client_id @client_secret = client_secret @connection_options = .fetch(:connection_options, {}) @connection_client = .fetch(:connection_client, OAuth2::HttpConnection) DEFAULTS_PATHS.keys.each do |key| instance_variable_set(:"@#{key}", .fetch(key, DEFAULTS_PATHS[key])) end end |
Instance Attribute Details
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def @authorize_path end |
#client_id ⇒ Object
Returns the value of attribute client_id.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def client_secret @client_secret end |
#connection_client ⇒ Object
Returns the value of attribute connection_client.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def connection_client @connection_client end |
#connection_options ⇒ Object
Returns the value of attribute connection_options.
4 5 6 |
# File 'lib/oauth2/client.rb', line 4 def @connection_options end |
#device_path ⇒ Object
Returns the value of attribute device_path.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def device_path @device_path end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/oauth2/client.rb', line 4 def host @host end |
#token_path ⇒ Object
Returns the value of attribute token_path.
5 6 7 |
# File 'lib/oauth2/client.rb', line 5 def token_path @token_path end |
Instance Method Details
#authorization_code ⇒ Object
51 52 53 |
# File 'lib/oauth2/client.rb', line 51 def OAuth2::Grant::AuthorizationCode.new(self) end |
#client_credentials ⇒ Object
59 60 61 |
# File 'lib/oauth2/client.rb', line 59 def client_credentials OAuth2::Grant::ClientCredentials.new(self) end |
#connection ⇒ Object
71 72 73 |
# File 'lib/oauth2/client.rb', line 71 def connection @connection ||= @connection_client.new(@host, @connection_options) end |
#device_code ⇒ Object
67 68 69 |
# File 'lib/oauth2/client.rb', line 67 def device_code OAuth2::Grant::DeviceCode.new(self) end |
#implicit ⇒ Object
47 48 49 |
# File 'lib/oauth2/client.rb', line 47 def implicit OAuth2::Grant::Implicit.new(self) end |
#normalize_scope(scope, sep = ' ') ⇒ Object
Token scope definitions vary by service e.g Google uses space delimited scopes, while Github uses comma seperated scopes. This method allows us to normalize the token scopes
40 41 42 43 44 45 |
# File 'lib/oauth2/client.rb', line 40 def normalize_scope(scope, sep=' ') unless (scope.is_a?(String) || scope.is_a?(Array)) raise ArgumentError.new("Expected scope of type String or Array but was: #{scope.class.name}") end (scope.is_a?(Array) && scope.join(sep)) || scope end |
#password ⇒ Object
63 64 65 |
# File 'lib/oauth2/client.rb', line 63 def password OAuth2::Grant::Password.new(self) end |
#refresh_token ⇒ Object
55 56 57 |
# File 'lib/oauth2/client.rb', line 55 def refresh_token OAuth2::Grant::RefreshToken.new(self) end |