doorkeeper-jwt icon indicating copy to clipboard operation
doorkeeper-jwt copied to clipboard

How to proceed when using multiple models for auth

Open jvalenciag opened this issue 7 years ago • 4 comments

I don't know how to make this gem work with multimple models for auth, how do I differentiate when generating the token?

jvalenciag avatar Oct 23 '18 04:10 jvalenciag

Could you explain your use case better ?

coalwater avatar Nov 01 '18 15:11 coalwater

I think @jvalenciag means multiple scopes like devise do.

phlegx avatar Apr 16 '19 14:04 phlegx

Same question here, we have either Driver or Client and I can find no way from the options hash that is yielded to the token_payload to the actual owner.

leehambley avatar Apr 23 '20 17:04 leehambley

I saw in the docs that token_payload could be configured. So you can add the "role" field or any field into access token as your expect.

User model: { id: int, email: string,  role: ["driver"] }  

Doorkeeper::JWT.configure do
  ...
  token_payload do |opts|
    user = User.find(opts[:resource_owner_id])

    {
      ...
      user: {
        id: user.id,
        email: user.email,
        role: user.role
      }
    }
  end
  ...
end

linhdangduy avatar Aug 23 '20 01:08 linhdangduy