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

Auth header is not being set in sign up when using confirmable with allowed unconfirmed access #361

Closed
virginia-rodriguez opened this issue Aug 28, 2015 · 3 comments

Comments

@virginia-rodriguez
Copy link
Contributor

On sign up, although unconfirmed access is configured, auth headers are not updated. So automatic sign in after sign up does not occurs (this works fine if confirmable module is not used).

I think it's because the following line: https://github.com/lynndylanhurley/devise_token_auth/blob/master/app/controllers/devise_token_auth/registrations_controller.rb#L51

unless @resource.confirmed?

should be replaced by:

!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?

just like it was replaced in colavitam@269e023

Is this correct?

@virginia-rodriguez virginia-rodriguez changed the title Auth header is not set in sign up when using confirmable with allowed unconfirmed access Auth header is not being set in sign up when using confirmable with allowed unconfirmed access Aug 28, 2015
@virginia-rodriguez
Copy link
Contributor Author

Well, I think that what I said before is not completely right. First of all the condition should be the opposite and also in that case confirmation email will not be sent.

So, I think something like this should be the right way to go:

         unless @resource.confirmed?
            @resource.send_confirmation_instructions({
              client_config: params[:config_name],
              redirect_url: redirect_url
            })
          end


          if !@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?

            # email auth has been bypassed, authenticate user
            @client_id = SecureRandom.urlsafe_base64(nil, false)
            @token     = SecureRandom.urlsafe_base64(nil, false)

            @resource.tokens[@client_id] = {
              token: BCrypt::Password.create(@token),
              expiry: (Time.now + DeviseTokenAuth.token_lifespan).to_i
            }

            @resource.save!

            update_auth_header
          end

@sgonyea
Copy link

sgonyea commented Sep 20, 2015

Thanks for reporting this, @virginia-rodriguez! I'm hitting this issue as well and am shutting off confirmable for the time being.

Would you like to create a PR for this? Your code appears to be correct.

@zachfeldman
Copy link
Contributor

Seems like this is solved? See #89 . Otherwise feel free to reopen.

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