Skip to content

Commit dea069c

Browse files
committed
Support Azure AD access token refresh
This adds a new optional property, `includeScopeInTokenRefresh`, which includes the configured `scope` in token refresh requests, as required by Azure AD. Fixes DuendeArchive#1264
1 parent bd94ff9 commit dea069c

4 files changed

+46
-0
lines changed

src/UserManager.js

+3
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ export class UserManager extends OidcClient {
165165
return this._loadUser().then(user => {
166166
if (user && user.refresh_token) {
167167
args.refresh_token = user.refresh_token;
168+
if (this.settings.includeScopeInTokenRefresh) {
169+
args.scope = this.settings.scope;
170+
}
168171
return this._useRefreshToken(args);
169172
}
170173
else {

src/UserManagerSettings.js

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export class UserManagerSettings extends OidcClientSettings {
2424
automaticSilentRenew = false,
2525
validateSubOnSilentRenew = false,
2626
includeIdTokenInSilentRenew = true,
27+
includeScopeInTokenRefresh = false,
2728
monitorSession = true,
2829
monitorAnonymousSession = false,
2930
checkSessionInterval = DefaultCheckSessionInterval,
@@ -48,6 +49,7 @@ export class UserManagerSettings extends OidcClientSettings {
4849
this._automaticSilentRenew = automaticSilentRenew;
4950
this._validateSubOnSilentRenew = validateSubOnSilentRenew;
5051
this._includeIdTokenInSilentRenew = includeIdTokenInSilentRenew;
52+
this._includeScopeInTokenRefresh = includeScopeInTokenRefresh;
5153
this._accessTokenExpiringNotificationTime = accessTokenExpiringNotificationTime;
5254

5355
this._monitorSession = monitorSession;
@@ -100,6 +102,9 @@ export class UserManagerSettings extends OidcClientSettings {
100102
get includeIdTokenInSilentRenew() {
101103
return this._includeIdTokenInSilentRenew;
102104
}
105+
get includeScopeInTokenRefresh() {
106+
return this._includeScopeInTokenRefresh;
107+
}
103108
get accessTokenExpiringNotificationTime() {
104109
return this._accessTokenExpiringNotificationTime;
105110
}

test/unit/UserManager.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ describe("UserManager", function () {
152152
return Promise.resolve()
153153
}
154154
subject.signinSilent({prompt:"foo"});
155+
});
156+
157+
it("should pass scope from settings when refreshing token if configured", function(done) {
158+
159+
stubUserStore.item = new User({refresh_token:"refresh_token"}).toStorageString();
160+
161+
settings.includeScopeInTokenRefresh = true;
162+
settings.scope = "scope";
163+
subject = new UserManager(settings);
164+
165+
subject._useRefreshToken = function(args){
166+
args.scope.should.equal("scope");
167+
done();
168+
return Promise.resolve()
169+
}
170+
subject.signinSilent();
155171
})
156172
});
157173

test/unit/UserManagerSettings.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ describe("UserManagerSettings", function () {
129129
});
130130
});
131131

132+
describe("includeScopeInTokenRefresh", function () {
133+
it("should return true value from initial settings", function () {
134+
let subject = new UserManagerSettings({
135+
includeScopeInTokenRefresh: true,
136+
});
137+
subject.includeScopeInTokenRefresh.should.be.true;
138+
});
139+
140+
it("should return false value from initial settings", function () {
141+
let subject = new UserManagerSettings({
142+
includeScopeInTokenRefresh: false,
143+
});
144+
subject.includeScopeInTokenRefresh.should.be.false;
145+
});
146+
147+
it("should use default value", function () {
148+
let subject = new UserManagerSettings({
149+
});
150+
subject.includeScopeInTokenRefresh.should.be.false;
151+
});
152+
});
153+
132154
describe("accessTokenExpiringNotificationTime", function () {
133155

134156
it("should return value from initial settings", function () {

0 commit comments

Comments
 (0)