doorkeeper-gem / doorkeeper-jwt

JWT Token support for Doorkeeper
MIT License
217 stars 45 forks source link

How to proceed when using multiple models for auth #29

Open jvalenciag opened 5 years ago

jvalenciag commented 5 years ago

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

coalwater commented 5 years ago

Could you explain your use case better ?

phlegx commented 5 years ago

I think @jvalenciag means multiple scopes like devise do.

leehambley commented 4 years ago

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.

linhdangduy commented 4 years ago

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