Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yielding Resource to Overriding Controller #548

Closed
bezreyhan opened this issue Feb 26, 2016 · 4 comments
Closed

Yielding Resource to Overriding Controller #548

bezreyhan opened this issue Feb 26, 2016 · 4 comments

Comments

@bezreyhan
Copy link

I'm trying to extend the create action for the Sessions Controller

When I do this:

class SessionsController < DeviseTokenAuth::SessionsController

  def create
    super do |resource|
      puts resource
    end
  end
end

resource == nil

however @resource does return the resource.

Is this the expected behavior?

Also, I was wondering how I can get access to the token that will be returned to the user? I was able to access it via @token.

@richardmable
Copy link

I literally just asked the same question! See #549
I've also had issues with not being able to pass a super block to a DeviseTokenAuth controller, doesn't seem to do anything, and I'm pretty sure I'm inheriting it correctly.

@richardmable
Copy link

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:
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)

I hope this helps, and also thanks to @JonathanWexler for helping to figure this out.

@bezreyhan
Copy link
Author

@richardmable thanks for documenting your findings @resource in not nil for me. Rather resourcem which should be returned by the block, is nil.

I am also able to get access to the token via @token

@zachfeldman
Copy link
Contributor

Sounds like we have a proposed solution here? Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants