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

Optional oauth on one point #58

Open
alexandru-calinoiu opened this issue May 18, 2016 · 3 comments
Open

Optional oauth on one point #58

alexandru-calinoiu opened this issue May 18, 2016 · 3 comments

Comments

@alexandru-calinoiu
Copy link

I have an enpoint that can work both authorized and not authorized, when I don't decorate it with oauth2 I can't seem to be able to get the resource_owner even when I pass the bearer token.

@antek-drzewiecki
Copy link
Owner

antek-drzewiecki commented Jun 1, 2016

That is true. Resource owner only gets set when an endpoint is authorized.
The scenario where an endpoint can be in both states was not taken account for.

@thedarkside
Copy link

i've monkeypatched wine_bouncer 0.3.1 some time ago this way:

module WineBouncer
  class OAuth2 < Grape::Middleware::Base

    #monkeypatch protection behavior. This method shares the given token with the endpoints even if they aren't protected.
    def before
      set_auth_strategy(WineBouncer.configuration.auth_strategy)
      auth_strategy.api_context = context
      #extend the context with auth methods.
      context.extend(WineBouncer::AuthMethods)
      context.protected_endpoint = endpoint_protected?
      self.doorkeeper_request= env # set request for later use.
      doorkeeper_authorize! *auth_scopes if context.protected_endpoint?
      context.doorkeeper_access_token = doorkeeper_token
    end
  end
end

it basically does what you want.
i didn't have time to contribute this as a pull request yet.

@dja
Copy link

dja commented Nov 2, 2018

This monkey patch works, but would love to see this properly considered within the gem. Have you rethought this @antek-drzewiecki?

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

4 participants