Create user access token via rails console

Hi,

I am trying to create a token via the rails console.
Type: User access token, not an OAuth 2.0 Token.

To identify the user Iwould start with.
u = User.find(**USERID**)

But then I am not sure what to use. Any help is much appreciated.

Thanks a lot,
Gijs

Not sure why you’d want to do that on console level because it’s much more complicated than UI.
Anyway… Token.create(user_id: 3, persistent: true, action: 'api', label: 'amazing!', preferences: {"permission"=>["ticket.agent"]}, created_at: Time.now, updated_at: Time.now) will create an API token for User-ID 3 which is persistant and has no expiration date. This token has ticket.agent permission.

Note that permission is an array and thus can hold several permissions if needed.
After creation you’ll want to check the name attribute for the token value.

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.