Search code examples
oauthunauthorizeddoorkeeper

Have latest Doorkeeper return 401 for unauthorized (reinstate old behaviour)


In the upgrade docs there's a note about the default response status moving from 401 to 400 (https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions#api-changes-2).

This is going to break my clients until we can get them to upgrade (/handle both cases in the short term).

How can I reinstate the 401 response until such a time as my clients can update?

Thanks!


Solution

  • You can check the changes made in https://github.com/doorkeeper-gem/doorkeeper/pull/1202/files and try to patch Doorkeeper::OAuth::ErrorResponse to return status you need. Then when you would be ready to migrate - just remove the patch. All you need is to overrida status method. Also check InvalidTokenResponse class, maybe you need to patch it too.

    There is no built-in option to switch status code in DOorkeeper so you can only patch its' internals.