class OAuth2Client::Client
Constants
- DEFAULTS_PATHS
Attributes
client_id[RW]
client_secret[RW]
connection_client[RW]
connection_options[R]
device_path[RW]
host[R]
token_path[RW]
Public Class Methods
new(host, client_id, client_secret, options={})
click to toggle source
# File lib/oauth2-client/client.rb, line 14 def initialize(host, client_id, client_secret, options={}) @host = host @client_id = client_id @client_secret = client_secret @connection_options = options.fetch(:connection_options, {}) @connection_client = options.fetch(:connection_client, OAuth2Client::HttpConnection) DEFAULTS_PATHS.keys.each do |key| instance_variable_set(:"@#{key}", options.fetch(key, DEFAULTS_PATHS[key])) end end
Public Instance Methods
client_credentials()
click to toggle source
# File lib/oauth2-client/client.rb, line 59 def client_credentials OAuth2Client::Grant::ClientCredentials.new(self) end
connection()
click to toggle source
# File lib/oauth2-client/client.rb, line 71 def connection @connection ||= @connection_client.new(@host, @connection_options) end
connection_options=(options)
click to toggle source
# File lib/oauth2-client/client.rb, line 30 def connection_options=(options) @connection = nil @connection_options = options end
device_code()
click to toggle source
# File lib/oauth2-client/client.rb, line 67 def device_code OAuth2Client::Grant::DeviceCode.new(self) end
host=(hostname)
click to toggle source
# File lib/oauth2-client/client.rb, line 25 def host=(hostname) @connection = nil @host = hostname end
implicit()
click to toggle source
# File lib/oauth2-client/client.rb, line 47 def implicit OAuth2Client::Grant::Implicit.new(self) end
normalize_scope(scope, sep=' ')
click to toggle source
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
@see developer.github.com/v3/oauth/#scopes, developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl
# File lib/oauth2-client/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()
click to toggle source
# File lib/oauth2-client/client.rb, line 63 def password OAuth2Client::Grant::Password.new(self) end
refresh_token()
click to toggle source
# File lib/oauth2-client/client.rb, line 55 def refresh_token OAuth2Client::Grant::RefreshToken.new(self) end