{"action":"created","issue":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/1160","repository_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper","labels_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/1160/labels{/name}","comments_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/1160/comments","events_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/1160/events","html_url":"https://github.com/doorkeeper-gem/doorkeeper/issues/1160","id":374008947,"node_id":"MDU6SXNzdWUzNzQwMDg5NDc=","number":1160,"title":"Compatibility with Devise","user":{"login":"MicMicMon","id":37897072,"node_id":"MDQ6VXNlcjM3ODk3MDcy","avatar_url":"https://avatars1.githubusercontent.com/u/37897072?v=4","gravatar_id":"","url":"https://api.github.com/users/MicMicMon","html_url":"https://github.com/MicMicMon","followers_url":"https://api.github.com/users/MicMicMon/followers","following_url":"https://api.github.com/users/MicMicMon/following{/other_user}","gists_url":"https://api.github.com/users/MicMicMon/gists{/gist_id}","starred_url":"https://api.github.com/users/MicMicMon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MicMicMon/subscriptions","organizations_url":"https://api.github.com/users/MicMicMon/orgs","repos_url":"https://api.github.com/users/MicMicMon/repos","events_url":"https://api.github.com/users/MicMicMon/events{/privacy}","received_events_url":"https://api.github.com/users/MicMicMon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-25T15:35:34Z","updated_at":"2018-11-08T14:36:53Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\nFresh install of devise & doorkeeper, for example following https://scotch.io/@jiggs/rails-api-doorkeeper-devise\r\n\r\nI was getting devise to work with doorkeeper (classic: frontend auth to rails API with login/password first, gets a token, then speaks with API using token).\r\n\r\nI struggled because whenever I used some of devise/RegistrationsController actions, it failed with an error message like \"You need to sign in or sign up before continuing\", even though \"Bearer xxxx\" was used in the header.\r\n\r\nIt turns out in Devise Registrations Controller, there is:\r\n```Ruby\r\nprepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]\r\n```\r\nwhich in turns is:\r\n```Ruby\r\n# Authenticates the current scope and gets the current resource from the session.\r\n  def authenticate_scope!\r\n    send(:\"authenticate_#{resource_name}!\", force: true)\r\n    self.resource = send(:\"current_#{resource_name}\")\r\n  end\r\n```\r\nThe first call is the one failing, because it does not call Doorkeeper as far as I understand.\r\nThe second one, it's easy to make it work defining my own functions in the Application Controller:\r\n```Ruby\r\n  def current_resource_owner\r\n    User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token\r\n  end\r\n\r\n  def current_user\r\n    current_resource_owner\r\n  end\r\n```\r\nThus, I overwrite the `authenticate_scope!` method in my own RegistrationsController, just removing the second line.\r\n\r\nThis way, everything works fine now.\r\n\r\n### Expected behavior\r\nShould work as Wiki explains.\r\n\r\n### Actual behavior\r\nDoes not, because of above as far as I understand.\r\n\r\n### My question\r\nIs my workaround safe? Is it the way to go? If so, is it a compatibility mismatch on Devise end, or Doorkeeper end?\r\n\r\nIf it is the way to go, I could go ahead and update the wiki (already did on https://github.com/doorkeeper-gem/doorkeeper/wiki/Using-Resource-Owner-Password-Credentials-flow because there lacked a test when `:confirmable` option is used in Devise), and/or post a bug report in Devise."},"comment":{"url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/comments/437014828","html_url":"https://github.com/doorkeeper-gem/doorkeeper/issues/1160#issuecomment-437014828","issue_url":"https://api.github.com/repos/doorkeeper-gem/doorkeeper/issues/1160","id":437014828,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzAxNDgyOA==","user":{"login":"nbulaj","id":1443426,"node_id":"MDQ6VXNlcjE0NDM0MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1443426?v=4","gravatar_id":"","url":"https://api.github.com/users/nbulaj","html_url":"https://github.com/nbulaj","followers_url":"https://api.github.com/users/nbulaj/followers","following_url":"https://api.github.com/users/nbulaj/following{/other_user}","gists_url":"https://api.github.com/users/nbulaj/gists{/gist_id}","starred_url":"https://api.github.com/users/nbulaj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nbulaj/subscriptions","organizations_url":"https://api.github.com/users/nbulaj/orgs","repos_url":"https://api.github.com/users/nbulaj/repos","events_url":"https://api.github.com/users/nbulaj/events{/privacy}","received_events_url":"https://api.github.com/users/nbulaj/received_events","type":"User","site_admin":false},"created_at":"2018-11-08T14:36:53Z","updated_at":"2018-11-08T14:36:53Z","author_association":"MEMBER","body":"Hi @MicMicMon . I don't sure I can help you with Devise because I don't use it (or do it very rarely), especially with Doorkeeper. And looks like you already solved your problem, because how do you think Devise knows about current resource without your overridden method (also you can use any authorization / authentication library with Devise and you need to overload it's controllers to implement required behavior)? Also maybe you can contact an author of the original article.."}}
{"actor":{"display_login":"nbulaj"}}