Skip to content

Commit

Permalink
Updated the facebook login_from to allow logins using the Facebook Ja…
Browse files Browse the repository at this point in the history
…vaScript SDK.
  • Loading branch information
mbillard committed Oct 5, 2012
1 parent be417c5 commit 63e7b84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
18 changes: 14 additions & 4 deletions lib/sorcery/controller/submodules/external/protocols/oauth2.rb
Expand Up @@ -19,11 +19,21 @@ def authorize_url(options = {})
end

def get_access_token(args, options = {})
raise ArgumentError, "either a `code` or an `access token` is necessary to build an Oauth2 AccessToken" if args[:code].nil? && args[:access_token].nil?

client = build_client(options)
client.auth_code.get_token(
args[:code],
{ :redirect_uri => @callback_url, :parse => options.delete(:parse) }, options
)

if args[:access_token]
hash = args
hash.merge!({:mode => options[:mode]}) if options[:mode]
hash.merge!({:param_name => options[:param_name]}) if options[:param_name]
::OAuth2::AccessToken.from_hash(client, hash)
else
client.auth_code.get_token(
args[:code],
{ :redirect_uri => @callback_url, :parse => options.delete(:parse) }, options
)
end
end

def build_client(options = {})
Expand Down
17 changes: 10 additions & 7 deletions lib/sorcery/controller/submodules/external/providers/facebook.rb
Expand Up @@ -72,14 +72,17 @@ def login_url(params,session)

# tries to login the user from access token
def process_callback(params,session)
unless (@access_token = params[:access_token]).nil?
args = {}
options = { :token_url => @token_url, :mode => @mode, :param_name => @param_name, :parse => @parse }
args.merge!({:code => params[:code]}) if params[:code]
@access_token = self.get_access_token(args, options)
end
args = {}
options = { :token_url => @token_url, :mode => @mode, :param_name => @param_name, :parse => @parse }

# server side callback params
args.merge!({:code => params[:code]}) if params[:code]

# client side callback params
args.merge!({:access_token => params[:access_token]}) if params[:access_token]
args.merge!({:expires_in => params[:expires_in]}) if params[:expires_in]

@access_token
@access_token = self.get_access_token(args, options)
end

end
Expand Down

0 comments on commit 63e7b84

Please sign in to comment.