Skip to content

Commit 6dc2bd9

Browse files
committed
1 parent cf1ba23 commit 6dc2bd9

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/lib/
2-
/src/adal.js
2+
/src/adal.js
3+
/src/adal.mod.js

CHANGELOG.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
#86 (thanks to @balanza)
2-
Adal SDK update to latest (1.0.18). Furthermore, I included a simple script to automatically fetch latest from github and clone it in our code.
1+
v. 0.5.0
2+
-
3+
+ update adal.js to 1.0.18
34

4-
Allow extra parameters while fetching token. This is to comply with SDK's acquireTokenRedirect and acquireTokenPopup signatures (with the latter being broken before the fix).
5-
6-
Using loginResource to check login token instead of clientId. This because SDK's AuthenticationContext constructor already handles missing loginResource by value it as clientId. Thus it can now cover both scenario: with both loginResource and clientId and only clientId provided.
75

6+
#86 (thanks to @balanza) https://github.com/salvoravida/react-adal/pull/86
7+
* Adal SDK update to latest (1.0.18). Furthermore, I included a simple script to automatically fetch latest from github and clone it in our code.
8+
* Allow extra parameters while fetching token. This is to comply with SDK's acquireTokenRedirect and acquireTokenPopup signatures (with the latter being broken before the fix).
9+
* Using loginResource to check login token instead of clientId. This because SDK's AuthenticationContext constructor already handles missing loginResource by value it as clientId. Thus it can now cover both scenario: with both loginResource and clientId and only clientId provided.
810

911
#33 https://github.com/salvoravida/react-adal/issues/33
12+
* login ok - permission failed fix infinite loop
1013

11-
login ok - permission failed fix infinite loop
14+
#67 https://github.com/salvoravida/react-adal/issues/67
15+
fix SSR support withAdalLogin Hoc
1216

13-
# fix SSR support withAdalLogin Hoc
17+
#68 https://github.com/salvoravida/react-adal/issues/68
18+
Clear the resource cache on new login

src/adal.mod.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import AuthenticationContext from './adal';
2+
3+
/**
4+
* Validates each resource token in cache againt current user
5+
*/
6+
AuthenticationContext.prototype.invalidateResourceTokens = function () {
7+
const idToken = this._getItem(this.CONSTANTS.STORAGE.IDTOKEN);
8+
if (!idToken) { return; }
9+
const { upn } = this._extractIdToken(idToken);
10+
const resources = Object.values(this.config.endpoints);
11+
12+
resources.forEach(r => this._clearStaleResourceToken(r, upn));
13+
}
14+
15+
/**
16+
* Clears cache for the given resource if it doesn't belong to current user's UPN
17+
* @param {string} currentUserUpn Unique user identifier
18+
* @param {string} resource a URI that identifies the resource
19+
*/
20+
AuthenticationContext.prototype._clearStaleResourceToken = function (resource, currentUserUpn) {
21+
const resourceToken = this.getCachedToken(resource);
22+
if (resourceToken) {
23+
const { upn } = this._extractIdToken(resourceToken);
24+
if (upn !== currentUserUpn) {
25+
this.info(`Clearing invalid cache of resource ${resource}`);
26+
this.clearCacheForResource(resource);
27+
}
28+
}
29+
}
30+
31+
export default AuthenticationContext

src/react-adal.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// eslint-disable-next-line
22
import React from 'react';
3-
import AuthenticationContext_ from './adal';
3+
import AuthenticationContext_ from './adal.mod';
44

55
const isSSR = typeof window === 'undefined';
66

@@ -63,6 +63,10 @@ export function runWithAdal(authContext, app, doNotLogin) {
6363
//it must run in iframe too for refreshToken (parsing hash and get token)
6464
authContext.handleWindowCallback();
6565

66+
// Clear the resource cache on new login
67+
// https://github.com/salvoravida/react-adal/issues/68
68+
authContext.invalidateResourceTokens();
69+
6670
//prevent iframe double app !!!
6771
if (window === window.parent) {
6872
if (!authContext.isCallback(window.location.hash)) {

0 commit comments

Comments
 (0)