Skip to content

Doorkeeper can be misleading when certain errors occur in custom token generators #943

Closed
@MarkMurphy

Description

@MarkMurphy

See my comment in the NoMethodError handler

# `access_token_mixin.rb`
  def generate_token
      self.created_at ||= Time.now.utc

      generator = Doorkeeper.configuration.access_token_generator.constantize
      self.token = generator.generate(
        resource_owner_id: resource_owner_id,
        scopes: scopes,
        application: application,
        expires_in: expires_in,
        created_at: created_at
      )
    rescue NoMethodError
      # Doorkeeper::JWT was trying to use `[]` on a null variable and thus a NoMethodError was raised. The error message returned here in this case was misleading because Doorkeeper::JWT does in fact respond to `.generate`
      raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
    rescue NameError
      raise Errors::TokenGeneratorNotFound, "#{generator} not found"
    end

Activity

anthonylebrun

anthonylebrun commented on Jun 2, 2017

@anthonylebrun

I believe I had just had this happen to me. I think the solution may be to use a throw a custom exception rather than use NoMethodError and explicitly check via respond_to?(:generate). Happy to do a PR if I get the green light.

Charizard

Charizard commented on Oct 5, 2017

@Charizard

Same here 👍

self-assigned this
on Feb 2, 2018
added a commit that references this issue on Mar 19, 2025

Fix doorkeeper-gem#943: proper Access Token value generation

384983e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @MarkMurphy@anthonylebrun@nbulaj@Charizard

      Issue actions

        Doorkeeper can be misleading when certain errors occur in custom token generators · Issue #943 · doorkeeper-gem/doorkeeper