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

resource_owner always required for Plug.VerifyHeader #40

Closed
Kuret opened this issue Sep 12, 2018 · 4 comments
Closed

resource_owner always required for Plug.VerifyHeader #40

Kuret opened this issue Sep 12, 2018 · 4 comments

Comments

@Kuret
Copy link
Collaborator

Kuret commented Sep 12, 2018

I'm trying use an application-wide bearer token (not bound to any user) to use for metadata endpoints and third party application connections.

I created a new OauthApplication with a client_id and client_secret (and set the resource_owner to the user that creates the application in the backend).

I can retrieve an access_token from the token endpoint using the client_credentials grant but I am unauthorized when going to an API endpoint. It appears resource_owner is explicitly set to nil in the client_credentials.grant flow:

client_credentials.ex is passing the client:

OauthAccessTokens.get_or_create_token(client, request["scope"], token_params)

oauth_access_tokens.ex get_or_create_token/3 explicitly sets the resource_owner to nil:

def get_or_create_token(%OauthApplication{} = application, scopes, attrs) do
    get_or_create_token(nil, application, scopes, attrs)
end

def get_or_create_token(resource_owner, application, scopes, attrs) do

The VerifyHeader plug then returns {:no_association_found} when resource_owner is nil

Is this intended or a bug?

@danschultzer
Copy link
Owner

Yeah, the resource_owner should be nil, otherwise it'll be an access token for a resource rather than application. It shouldn't return {:no_association_found} but instead just load the associated application. I'll double check this, and open a PR when I've got some free time 🙂

@danschultzer
Copy link
Owner

Added a quick PR that you can try out. I haven't dug into the specification to be sure that this is how it should work, but this might be what you need to continue your work.

@Kuret
Copy link
Collaborator Author

Kuret commented Sep 13, 2018

Works, exactly what I needed to continue. Thanks for the quick response & PR!

@danschultzer
Copy link
Owner

v0.4.3 is out!

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