2010-07-13 06:17:25 -04:00
|
|
|
require 'active_support/core_ext/array/wrap'
|
|
|
|
|
2010-07-13 04:09:55 -04:00
|
|
|
module Devise
|
|
|
|
module Oauth
|
|
|
|
class Config
|
2010-07-13 06:17:25 -04:00
|
|
|
attr_reader :name, :scope, :client
|
2010-07-13 04:09:55 -04:00
|
|
|
|
2010-07-13 06:17:25 -04:00
|
|
|
def initialize(name, app_id, app_secret, options)
|
|
|
|
@name = name
|
|
|
|
@scope = Array.wrap(options.delete(:scope))
|
2010-07-13 04:09:55 -04:00
|
|
|
@client = OAuth2::Client.new(app_id, app_secret, options)
|
|
|
|
end
|
2010-07-13 06:17:25 -04:00
|
|
|
|
|
|
|
def authorize_url(options)
|
|
|
|
options[:scope] ||= @scope.join(',')
|
|
|
|
client.web_server.authorize_url(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_token_by_code(code)
|
|
|
|
client.web_server.get_access_token(code)
|
|
|
|
end
|
|
|
|
|
|
|
|
def access_token_by_token(token)
|
|
|
|
OAuth2::AccessToken.new(client, token)
|
|
|
|
end
|
2010-07-13 04:09:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|