I'm trying to allow API access by passing an access_token as a parameter in a request. Normally I am using the Facebook JS login to create a cookie that omniauth-facebook then reads and generates an env['omniauth.auth']. I have a class method on my User model that creates or updates a user based on this.
I'd like to be able to do the same for new/existing users passing just an access_token (e.g. from my iOS app). Currently I am doing the following (ugly):
facebook = OmniAuth::Strategies::Facebook.new(nil)
client = OAuth2::Client.new(nil, nil, facebook.options.client_options)
facebook.access_token = OAuth2::AccessToken.new(client, token, facebook.options.access_token_options)
from_auth(facebook.auth_hash)
(the first 3 lines essentially recreate the auth hash from an access_token.)
This code seems super long-winded and ugly, is there a nicer way to do this? (it must be a common use-case).
All I really want to do is provide authentication in the usual way to web browser users, then another access_token based authentication for apps interacting with my REST API (standard Rails).
Many thanks.
I'm trying to allow API access by passing an
access_tokenas a parameter in a request. Normally I am using the Facebook JS login to create a cookie that omniauth-facebook then reads and generates anenv['omniauth.auth']. I have a class method on my User model that creates or updates a user based on this.I'd like to be able to do the same for new/existing users passing just an
access_token(e.g. from my iOS app). Currently I am doing the following (ugly):(the first 3 lines essentially recreate the auth hash from an access_token.)
This code seems super long-winded and ugly, is there a nicer way to do this? (it must be a common use-case).
All I really want to do is provide authentication in the usual way to web browser users, then another
access_tokenbased authentication for apps interacting with my REST API (standard Rails).Many thanks.