Skip to content

Commit f9ef86b

Browse files
committed
feat(api): send the scope when refreshing the access token
1 parent 3a43b57 commit f9ef86b

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

api/src/identity-access-management/application/token/token.controller.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ const createToken = async function (request, h, dependencies = { tokenService })
3232
if (grantType === 'refresh_token') {
3333
refreshToken = request.payload.refresh_token;
3434

35-
// TODO: we should pass the scope when ember-simple-auth will pass it
36-
// see https://github.com/mainmatter/ember-simple-auth/pull/2813 for further details
37-
const tokensInfo = await usecases.createAccessTokenFromRefreshToken({ refreshToken });
35+
const tokensInfo = await usecases.createAccessTokenFromRefreshToken({ refreshToken, scope });
3836

3937
accessToken = tokensInfo.accessToken;
4038
expirationDelaySeconds = tokensInfo.expirationDelaySeconds;

api/tests/identity-access-management/acceptance/application/token.route.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,42 @@ describe('Acceptance | Identity Access Management | Route | Token', function ()
143143
expect(result.user_id).to.equal(userId);
144144
expect(result.refresh_token).to.exist;
145145
});
146+
147+
context('when the scope is different from the refresh token one', function () {
148+
it('returns a 401 (unauthorized)', async function () {
149+
// given
150+
const { result: accessTokenResult } = await server.inject({
151+
method: 'POST',
152+
url: '/api/token',
153+
headers: {
154+
'content-type': 'application/x-www-form-urlencoded',
155+
},
156+
payload: querystring.stringify({
157+
grant_type: 'password',
158+
username: userEmailAddress,
159+
password: userPassword,
160+
scope: 'pix-orga',
161+
}),
162+
});
163+
164+
// when
165+
const response = await server.inject({
166+
method: 'POST',
167+
url: '/api/token',
168+
headers: {
169+
'content-type': 'application/x-www-form-urlencoded',
170+
},
171+
payload: querystring.stringify({
172+
grant_type: 'refresh_token',
173+
refresh_token: accessTokenResult.refresh_token,
174+
scope: 'pix-admin',
175+
}),
176+
});
177+
178+
// then
179+
expect(response.statusCode).to.equal(401);
180+
});
181+
});
146182
});
147183

148184
context('when scope is admin', function () {

api/tests/identity-access-management/unit/application/token.controller.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe('Unit | Identity Access Management | Application | Controller | Token',
100100

101101
sinon
102102
.stub(usecases, 'createAccessTokenFromRefreshToken')
103-
.withArgs({ refreshToken })
103+
.withArgs({ refreshToken, scope })
104104
.resolves({ accessToken, expirationDelaySeconds });
105105

106106
const tokenServiceStub = { extractUserId: sinon.stub() };

0 commit comments

Comments
 (0)