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

fix: fosite refresh scope narrowing e2e #3403

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cypress/integration/oauth2/refresh_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,46 @@ describe("The OAuth 2.0 Refresh Token Grant", function () {
})
})
})

it("should narrow and broaden Refresh Token scope correctly", function () {
const referrer = `${Cypress.env("client_url")}/empty`
cy.visit(referrer, {
failOnStatusCode: false,
})

createClient({
scope: "offline_access openid foo bar baz",
redirect_uris: [referrer],
grant_types: ["authorization_code", "refresh_token"],
response_types: ["code"],
token_endpoint_auth_method: "none",
}).then((client) => {
cy.authCodeFlowBrowser(client, {
consent: { scope: ["offline_access", "openid", "foo", "bar", "baz"] },
createClient: false,
}).then((originalResponse) => {
expect(originalResponse.status).to.eq(200)
expect(originalResponse.body.refresh_token).to.not.be.empty
expect(originalResponse.body.scope).to.equal("offline_access openid foo bar baz")

const originalToken = originalResponse.body.refresh_token

cy.refreshTokenBrowserScope(client, originalToken, "offline_access openid foo").then((refreshedResponse) => {
expect(refreshedResponse.status).to.eq(200)
expect(refreshedResponse.body.refresh_token).to.not.be.empty
expect(refreshedResponse.body.scope).to.equal("offline_access openid foo")

const refreshedToken = refreshedResponse.body.refresh_token

cy.refreshTokenBrowserScope(client, refreshedToken, "offline_access openid foo bar").then((finalRefreshedResponse) => {
expect(finalRefreshedResponse.status).to.eq(200)
expect(finalRefreshedResponse.body.refresh_token).to.not.be.empty
expect(finalRefreshedResponse.body.scope).to.equal("offline_access openid foo bar")
},
)
},
)
})
})
})
})
15 changes: 15 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,18 @@ Cypress.Commands.add("refreshTokenBrowser", (client, token) =>
failOnStatusCode: false,
}),
)

Cypress.Commands.add("refreshTokenBrowserScope", (client, token, scope) =>
cy.request({
url: `${Cypress.env("public_url")}/oauth2/token`,
method: "POST",
form: true,
body: {
grant_type: "refresh_token",
client_id: client.client_id,
refresh_token: token,
scope: scope,
},
failOnStatusCode: false,
}),
)
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/ory/fosite => github.com/james-d-elliott/fosite v0.42.2-0.20230102000600-1b13725b7055
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/james-d-elliott/fosite v0.42.2-0.20230102000600-1b13725b7055 h1:O7o+kTtgNjE1ITdljrxhJIiq6EV3Mylr9aGKzWbtYIQ=
github.com/james-d-elliott/fosite v0.42.2-0.20230102000600-1b13725b7055/go.mod h1:o/G4kAeNn65l6MCod2+KmFfU6JQBSojS7eXys6lKGzM=
github.com/jandelgado/gcov2lcov v1.0.4/go.mod h1:NnSxK6TMlg1oGDBfGelGbjgorT5/L3cchlbtgFYZSss=
github.com/jandelgado/gcov2lcov v1.0.5 h1:rkBt40h0CVK4oCb8Dps950gvfd1rYvQ8+cWa346lVU0=
github.com/jandelgado/gcov2lcov v1.0.5/go.mod h1:NnSxK6TMlg1oGDBfGelGbjgorT5/L3cchlbtgFYZSss=
Expand Down Expand Up @@ -822,8 +824,6 @@ github.com/ory/analytics-go/v4 v4.0.3 h1:2zNBQLlm3UiD8U7DdUGLLUBm62ZA5GtbEJ3S5U+
github.com/ory/analytics-go/v4 v4.0.3/go.mod h1:A3Chm/3TmM8jw4nqRss+gFhAYHRI5j/HFYH3C1FRahU=
github.com/ory/dockertest/v3 v3.9.1 h1:v4dkG+dlu76goxMiTT2j8zV7s4oPPEppKT8K8p2f1kY=
github.com/ory/dockertest/v3 v3.9.1/go.mod h1:42Ir9hmvaAPm0Mgibk6mBPi7SFvTXxEcnztDYOJ//uM=
github.com/ory/fosite v0.44.0 h1:Z3UjyO11/wlIoa3BotOqcTkfm7kUNA8F7dd8mOMfx0o=
github.com/ory/fosite v0.44.0/go.mod h1:o/G4kAeNn65l6MCod2+KmFfU6JQBSojS7eXys6lKGzM=
github.com/ory/go-acc v0.2.6/go.mod h1:4Kb/UnPcT8qRAk3IAxta+hvVapdxTLWtrr7bFLlEgpw=
github.com/ory/go-acc v0.2.8 h1:rOHHAPQjf0u7eHFGWpiXK+gIu/e0GRSJNr9pDukdNC4=
github.com/ory/go-acc v0.2.8/go.mod h1:iCRZUdGb/7nqvSn8xWZkhfVrtXRZ9Wru2E5rabCjFPI=
Expand Down