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

Use intersection of application and default server scopes #1002 #1086

Merged
merged 1 commit into from
Apr 21, 2018

Conversation

rishabhsairawat
Copy link
Contributor

@rishabhsairawat rishabhsairawat commented Apr 20, 2018

Summary

This PR aims to solve the issue #1002 .

Reference

Commit b5bf40e by @nbulaj missed the following case:
Default scopes: public, admin
Application scopes: read, write, public
And no scopes are passed.
Expected output: public
Output by b5bf40e : invalid scope

@nbulaj
Copy link
Member

nbulaj commented Apr 20, 2018

What about other grant flows, ie client credentials? I think they must work the same way

@nbulaj nbulaj merged commit 099f1e0 into doorkeeper-gem:master Apr 21, 2018
@rishabhsairawat
Copy link
Contributor Author

@nbulaj Yes, Other grant flows must work the same way.

nbulaj added a commit that referenced this pull request Apr 23, 2018
Build scopes (from request, intersection with application scopes or
server default) in BaseRequest. Add specs for Client Credentials and
Password grant flows.
@nbulaj
Copy link
Member

nbulaj commented Apr 23, 2018

@rishabhsairawat yep, this is a good strategy. Implemented in 976b235

@rishabhsairawat
Copy link
Contributor Author

@nbulaj What about other grant flows i.e. authorization_code & implicit? I think they must work the same way.

And you missed following case for client_credentials flow:
When application scopes are present but differs from configured default scopes
Output should be an error and it should not issue a token But according to you commit 976b235 it does not give error and issues a token.

@nbulaj
Copy link
Member

nbulaj commented Apr 23, 2018

What about other grant flows i.e. authorization_code & implici

I'm currently looking into them.

And you missed following case for client_credentials flow:

I will check it tomorrow.

rishabhsairawat added a commit to rishabhsairawat/doorkeeper that referenced this pull request Apr 24, 2018
@rishabhsairawat
Copy link
Contributor Author

rishabhsairawat commented Apr 24, 2018

@nbulaj Checkout following scenario:
When there is no application scope and no default scope present
Currently, Doorkeeper issues AccessToken without any scope
Wouldn't it be better to show error ?
And Same is With AccessGrant

nbulaj added a commit that referenced this pull request Apr 24, 2018
#1086: build scopes intersection in PreAuthorization for AuthorizationCode and Implicit flow
@nbulaj
Copy link
Member

nbulaj commented Apr 24, 2018

When there is no application scope and no default scope present
Currently, Doorkeeper issues AccessToken without any scope
Wouldn't it be better to show error ?
And Same is With AccessGrant

I don't sure if it must work this way. Some endpoints can require OAuth authentication, but without any particular scopes (just to be sure client is authenticated). So if client doesn't request any scopes - he will not get this scopes and can't request something protected with the scopes, but can interact with scopesless endpoints.

@rishabhsairawat
Copy link
Contributor Author

@nbulaj If you want this then I think In following case also, scopeless token and grant should be issued.

If intersection of application scopes and default scopes is blank and No scopes are passed in request
Intersection of application scopes and default scopes will be blank in following cases

  1. If default scopes are not present then intersection will automatically be blank
  2. If default scopes are present but differs from application scopes

@nbulaj
Copy link
Member

nbulaj commented May 3, 2018

@rishabhsairawat of I understood you correctly:

If intersection of application scopes and default scopes is blank and No scopes are passed in request
Intersection of application scopes and default scopes will be blank in following cases

If default scopes are not present then intersection will automatically be blank
If default scopes are present but differs from application scopes

then I think it already works this way.

context 'when application scopes contain some of the default scopes and no scope is passed' do
  before do
    client.update_attributes(scopes: 'value1 value2')
  end

  it 'issues new token with one default scope that are present in application scopes' do
    default_scopes_exist :value3

    headers = authorization client.uid, client.secret
    params  = { grant_type: 'client_credentials' }

    expect do
      post '/oauth/token', params: params, headers: headers
    end.to change { Doorkeeper::AccessToken.count }.by(1)

    token = Doorkeeper::AccessToken.first

    expect(token.application_id).to eq client.id
    expect(token.scopes).to be_empty

    should_have_json 'access_token', token.token
    should_not_have_json 'scope'
 end
end

@rishabhsairawat
Copy link
Contributor Author

@nbulaj Currently it works this way only for client_credentials flow as changes for client_credentials was done in your commit 976b235. But in my commits for other grant flows , I used other approach (showing error in place of token without any scope).

rishabhsairawat added a commit to rishabhsairawat/doorkeeper that referenced this pull request May 3, 2018
… of application scopes and default scopes to be blank
rishabhsairawat added a commit to rishabhsairawat/doorkeeper that referenced this pull request May 3, 2018
…n of application scopes and default scopes to be blank
@nbulaj
Copy link
Member

nbulaj commented May 3, 2018

Ah, thats ok @rishabhsairawat, I've checked only client credentials thinking that every grant works the same way. Thanks!

nbulaj added a commit that referenced this pull request May 3, 2018
#1086: provides scopeless token in case of intersection of applicatio…
thromera pushed a commit to thromera/doorkeeper that referenced this pull request May 29, 2018
…n of application scopes and default scopes to be blank
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

Successfully merging this pull request may close these issues.

2 participants