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

Can't save JWT token Doorkeeper::AccessToken. token length too long in mysql #31

Closed
harisr92 opened this issue Jun 13, 2019 · 2 comments

Comments

@harisr92
Copy link

harisr92 commented Jun 13, 2019

Hi,

Having issue when creating access token. It is trying to save the entire token to DB. Which result in
column too long error in MySQL.

Doorkeeper config

Doorkeeper.configure do
  orm :active_record
  resource_owner_authenticator do
    current_user || warden.authenticate!(scope: :user)
  end

  admin_authenticator do
    if current_user
      unless current_user.is_admin?
        redirect_to root_url
      end
    else
      redirect_to new_user_session_path
    end
  end

  access_token_generator '::Doorkeeper::JWT'

  enforce_configured_scopes
  default_scopes  :read
  optional_scopes :write, :update
end

JWT config

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

    {
      iss: 'Test',
      iat: Time.current.utc.to_i,

      # @see JWT reserved claims - https://tools.ietf.org/html/draft-jones-json-web-token-07#page-7
      jti: SecureRandom.uuid,

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

  # Optionally set additional headers for the JWT. See
  # https://tools.ietf.org/html/rfc7515#section-4.1
  token_headers do |opts|
    { kid: opts[:application][:uid] }
  end
  use_application_secret true
  encryption_method :hs512
end

When I try to get access token, its throwing MySQL error

Mysql2::Error: Data too long for column 'token' at row 1
@harisr92
Copy link
Author

Hi,
I solved this issue by setting token as text and removed unique index on the field, since I found its not very useful in setting unique index on text field.

@nbulaj
Copy link
Member

nbulaj commented Jun 26, 2019

@nbulaj nbulaj closed this as completed Jun 26, 2019
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

2 participants