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

is_fully_authenticated? returns true when the user model is not called user #190

Open
ostigley opened this issue Jun 8, 2020 · 2 comments

Comments

@ostigley
Copy link

ostigley commented Jun 8, 2020

Firstly thanks for this gem, it has, for the most part, been excellent to use.

Issue

calling the helper is_fully_authenticated? when the resource is not called user, always returns true.

Background

We have been refactoring a few of our authentication processes, and I have discovered that is_fully_authenticated? will return true if your user model is not called user.

Example

One of our user models is called admin. In one our our exposed devise controllers, we are calling the following to ensure two_factor is required:

warden.session(resource_name)[TwoFactorAuthentication::NEED_AUTHENTICATION] = true if warden.authenticated? resource_name

The session is now:

{
  "session_id" => "e506f931c02b42d17b398af55e95387a",
  "_csrf_token" => "esijVCN7Yf/y3/vExmc5Ci1t3ydcZe72EQ0HhpEF8lE=",
  "warden.user.admin.key" => [[1], "$2a$11$g84JZdWomFd6O6h9Ym6E2e"],
  "warden.user.admin.session" => {"need_two_factor_authentication"=>true}
}

But now, is_fully_authenticated? returns true because it runs this check:

!session["warden.user.user.session"].try(:[], TwoFactorAuthentication::NEED_AUTHENTICATION)

It should be returning false. Note the warden.user.user instead of the warden.user.admin

Proposed fix

The helper should be:

!session["warden.user.admin.session"].try(:[], TwoFactorAuthentication::NEED_AUTHENTICATION)

In theory, this could be achieved with

!session["warden.user.#{resource_name}.session"].try(:[], TwoFactorAuthentication::NEED_AUTHENTICATION)

If I am correct please let me know and I will attempt to make a pr for you. Otherwise any suggestions to my implementation are welcome.

@BenjaminBenetti
Copy link

+1 we have been using your proposed fix in our app with multiple devise user types.

@Houdini
Copy link
Owner

Houdini commented Jun 11, 2020

Thanks, I'll will fix it in next few days

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