mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
33 lines
No EOL
911 B
Ruby
33 lines
No EOL
911 B
Ruby
require 'active_support/core_ext/array/wrap'
|
|
|
|
module Devise
|
|
module Oauth
|
|
# A configuration object that holds the OAuth2::Client object
|
|
# and all configuration values given config.oauth.
|
|
class Config
|
|
attr_reader :scope, :client
|
|
|
|
def initialize(app_id, app_secret, options)
|
|
@scope = Array.wrap(options.delete(:scope))
|
|
@client = OAuth2::Client.new(app_id, app_secret, options)
|
|
end
|
|
|
|
def authorize_url(options)
|
|
options[:scope] ||= @scope.join(',')
|
|
client.web_server.authorize_url(options)
|
|
end
|
|
|
|
def access_token_by_code(code, redirect_uri=nil)
|
|
client.web_server.get_access_token(code, :redirect_uri => redirect_uri)
|
|
end
|
|
|
|
def access_token_by_token(token)
|
|
OAuth2::AccessToken.new(client, token)
|
|
end
|
|
|
|
def build_connection(&block)
|
|
client.connection.build(&block)
|
|
end
|
|
end
|
|
end
|
|
end |