Reputation: 11
How do I access the access token of the omniauth provider that should be sent back after successful authentication with the devise_token_auth gem and ng-token-auth with angular? I'd like to store this token to make future requests to the omniauth provider for updating information. The omniauth provider specifically is Strava. I see that devise_token_auth is creating its own access tokens, but those aren't for accessing Strava. Also I have no idea even where devise token auth pulls in the information from Strava even after reading through the gem's code. Seems like this should be a pretty simple thing, I can't be the only one who wants this information returned. Thanks in advance.
Upvotes: 0
Views: 1159
Reputation: 11
We have been able to figure this out with a lot of experimentation. @resouce
does return nil for us too, but we did find the access-token and all the other information returned from the omniauth provider, located in request.env['omniauth.auth']
, located in the redirect_callbacks
action of the OmniAuthCallbacks
controller. We also needed to set up
mount_devise_token_auth_for 'User', at: 'auth', controllers: { omniauth_callbacks: 'registrations'}
in routes.rb
, and create the custom controller which we named RegistrationsController.
So our block looked like this
class RegistrationsController < DeviseTokenAuth::OmniauthCallbacksController
def redirect_callbacks
super
puts "REDIRECT:"
puts request.env['omniauth.params']
puts "AUTH INFO"
puts request.env['omniauth.auth'].credentials['token']
puts "REDIRECT END"
# create the user_strava_key and save it.
@strava_token = request.env['omniauth.auth'].credentials['token']
UserStravaKey.create(key_secret: @strava_token)
end
end
Upvotes: 1