ra-auth-auth0 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/authProvider.d.ts +1 -2
- package/esm/authProvider.d.ts.map +1 -1
- package/esm/authProvider.js +12 -12
- package/esm/httpClient.d.ts +1 -1
- package/esm/httpClient.d.ts.map +1 -1
- package/esm/httpClient.js +1 -1
- package/lib/authProvider.d.ts +1 -2
- package/lib/authProvider.d.ts.map +1 -1
- package/lib/authProvider.js +13 -13
- package/lib/httpClient.d.ts +1 -1
- package/lib/httpClient.d.ts.map +1 -1
- package/lib/httpClient.js +2 -2
- package/package.json +2 -5
- package/src/authProvider.ts +11 -10
- package/src/httpClient.ts +1 -1
package/esm/authProvider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthProvider } from '
|
|
1
|
+
import { AuthProvider } from 'ra-core';
|
|
2
2
|
import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
3
3
|
/**
|
|
4
4
|
* An authProvider which handles authentication via the Auth0 instance.
|
|
@@ -24,7 +24,6 @@ import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
|
24
24
|
*
|
|
25
25
|
* const authProvider = Auth0AuthProvider(clientAuth0, {
|
|
26
26
|
* loginRedirectUri: 'http://localhost:3000/auth-callback',
|
|
27
|
-
* logoutRedirectUri: 'http://localhost:3000',
|
|
28
27
|
* });
|
|
29
28
|
*
|
|
30
29
|
* const App = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authProvider.d.ts","sourceRoot":"","sources":["../src/authProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,
|
|
1
|
+
{"version":3,"file":"authProvider.d.ts","sourceRoot":"","sources":["../src/authProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,eAAO,MAAM,iBAAiB,WAClB,WAAW;uBAMI,MAAM;wBACL,MAAM;0BACJ,OAAO;MAIlC,YAqFD,CAAC"}
|
package/esm/authProvider.js
CHANGED
|
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
import { PreviousLocationStorageKey } from '
|
|
37
|
+
import { PreviousLocationStorageKey } from 'ra-core';
|
|
38
38
|
/**
|
|
39
39
|
* An authProvider which handles authentication via the Auth0 instance.
|
|
40
40
|
*
|
|
@@ -59,7 +59,6 @@ import { PreviousLocationStorageKey } from 'react-admin';
|
|
|
59
59
|
*
|
|
60
60
|
* const authProvider = Auth0AuthProvider(clientAuth0, {
|
|
61
61
|
* loginRedirectUri: 'http://localhost:3000/auth-callback',
|
|
62
|
-
* logoutRedirectUri: 'http://localhost:3000',
|
|
63
62
|
* });
|
|
64
63
|
*
|
|
65
64
|
* const App = () => {
|
|
@@ -106,11 +105,13 @@ export var Auth0AuthProvider = function (client, _a) {
|
|
|
106
105
|
logout: function () {
|
|
107
106
|
return __awaiter(this, void 0, void 0, function () {
|
|
108
107
|
return __generator(this, function (_a) {
|
|
109
|
-
return [2 /*return*/, client
|
|
108
|
+
return [2 /*return*/, client
|
|
109
|
+
.logout({
|
|
110
110
|
logoutParams: {
|
|
111
111
|
returnTo: logoutRedirectUri || window.location.origin,
|
|
112
112
|
},
|
|
113
|
-
})
|
|
113
|
+
})
|
|
114
|
+
.then(function () { return logoutRedirectUri || '/'; })];
|
|
114
115
|
});
|
|
115
116
|
});
|
|
116
117
|
},
|
|
@@ -140,13 +141,13 @@ export var Auth0AuthProvider = function (client, _a) {
|
|
|
140
141
|
}
|
|
141
142
|
if (redirectOnCheckAuth) {
|
|
142
143
|
localStorage.setItem(PreviousLocationStorageKey, window.location.href);
|
|
143
|
-
client.loginWithRedirect({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
return [2 /*return*/, client.loginWithRedirect({
|
|
145
|
+
authorizationParams: {
|
|
146
|
+
redirect_uri: loginRedirectUri !== null && loginRedirectUri !== void 0 ? loginRedirectUri : "".concat(window.location.origin, "/auth-callback"),
|
|
147
|
+
},
|
|
148
|
+
})];
|
|
148
149
|
}
|
|
149
|
-
|
|
150
|
+
throw new Error('Unauthorized');
|
|
150
151
|
}
|
|
151
152
|
});
|
|
152
153
|
});
|
|
@@ -211,8 +212,7 @@ export var Auth0AuthProvider = function (client, _a) {
|
|
|
211
212
|
return [2 /*return*/];
|
|
212
213
|
case 3:
|
|
213
214
|
error_1 = _a.sent();
|
|
214
|
-
|
|
215
|
-
throw error_1;
|
|
215
|
+
throw { redirectTo: false, message: error_1.message };
|
|
216
216
|
case 4: throw new Error('Failed to handle login callback.');
|
|
217
217
|
}
|
|
218
218
|
});
|
package/esm/httpClient.d.ts
CHANGED
package/esm/httpClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,UAAU,gBAAiB,GAAG,WAClC,GAAG,WACC,WAAW,OAAO,GAAG,SAAS;;;;;EAQ1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACjB,MAAM,GAAG,IAAI,WACX,WAAW,OAAO,GAAG,SAAS,KACxC,OASF,CAAC"}
|
package/esm/httpClient.js
CHANGED
|
@@ -45,7 +45,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
import { fetchUtils } from '
|
|
48
|
+
import { fetchUtils } from 'ra-core';
|
|
49
49
|
/**
|
|
50
50
|
* An httpClient that adds authentication headers needed by Auth0 in all requests.
|
|
51
51
|
* @param auth0Client the Auth0 client.
|
package/lib/authProvider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthProvider } from '
|
|
1
|
+
import { AuthProvider } from 'ra-core';
|
|
2
2
|
import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
3
3
|
/**
|
|
4
4
|
* An authProvider which handles authentication via the Auth0 instance.
|
|
@@ -24,7 +24,6 @@ import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
|
24
24
|
*
|
|
25
25
|
* const authProvider = Auth0AuthProvider(clientAuth0, {
|
|
26
26
|
* loginRedirectUri: 'http://localhost:3000/auth-callback',
|
|
27
|
-
* logoutRedirectUri: 'http://localhost:3000',
|
|
28
27
|
* });
|
|
29
28
|
*
|
|
30
29
|
* const App = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authProvider.d.ts","sourceRoot":"","sources":["../src/authProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,
|
|
1
|
+
{"version":3,"file":"authProvider.d.ts","sourceRoot":"","sources":["../src/authProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA8B,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,eAAO,MAAM,iBAAiB,WAClB,WAAW;uBAMI,MAAM;wBACL,MAAM;0BACJ,OAAO;MAIlC,YAqFD,CAAC"}
|
package/lib/authProvider.js
CHANGED
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.Auth0AuthProvider = void 0;
|
|
40
|
-
var
|
|
40
|
+
var ra_core_1 = require("ra-core");
|
|
41
41
|
/**
|
|
42
42
|
* An authProvider which handles authentication via the Auth0 instance.
|
|
43
43
|
*
|
|
@@ -62,7 +62,6 @@ var react_admin_1 = require("react-admin");
|
|
|
62
62
|
*
|
|
63
63
|
* const authProvider = Auth0AuthProvider(clientAuth0, {
|
|
64
64
|
* loginRedirectUri: 'http://localhost:3000/auth-callback',
|
|
65
|
-
* logoutRedirectUri: 'http://localhost:3000',
|
|
66
65
|
* });
|
|
67
66
|
*
|
|
68
67
|
* const App = () => {
|
|
@@ -109,11 +108,13 @@ var Auth0AuthProvider = function (client, _a) {
|
|
|
109
108
|
logout: function () {
|
|
110
109
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
110
|
return __generator(this, function (_a) {
|
|
112
|
-
return [2 /*return*/, client
|
|
111
|
+
return [2 /*return*/, client
|
|
112
|
+
.logout({
|
|
113
113
|
logoutParams: {
|
|
114
114
|
returnTo: logoutRedirectUri || window.location.origin,
|
|
115
115
|
},
|
|
116
|
-
})
|
|
116
|
+
})
|
|
117
|
+
.then(function () { return logoutRedirectUri || '/'; })];
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
},
|
|
@@ -142,14 +143,14 @@ var Auth0AuthProvider = function (client, _a) {
|
|
|
142
143
|
return [2 /*return*/];
|
|
143
144
|
}
|
|
144
145
|
if (redirectOnCheckAuth) {
|
|
145
|
-
localStorage.setItem(
|
|
146
|
-
client.loginWithRedirect({
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
localStorage.setItem(ra_core_1.PreviousLocationStorageKey, window.location.href);
|
|
147
|
+
return [2 /*return*/, client.loginWithRedirect({
|
|
148
|
+
authorizationParams: {
|
|
149
|
+
redirect_uri: loginRedirectUri !== null && loginRedirectUri !== void 0 ? loginRedirectUri : "".concat(window.location.origin, "/auth-callback"),
|
|
150
|
+
},
|
|
151
|
+
})];
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
+
throw new Error('Unauthorized');
|
|
153
154
|
}
|
|
154
155
|
});
|
|
155
156
|
});
|
|
@@ -214,8 +215,7 @@ var Auth0AuthProvider = function (client, _a) {
|
|
|
214
215
|
return [2 /*return*/];
|
|
215
216
|
case 3:
|
|
216
217
|
error_1 = _a.sent();
|
|
217
|
-
|
|
218
|
-
throw error_1;
|
|
218
|
+
throw { redirectTo: false, message: error_1.message };
|
|
219
219
|
case 4: throw new Error('Failed to handle login callback.');
|
|
220
220
|
}
|
|
221
221
|
});
|
package/lib/httpClient.d.ts
CHANGED
package/lib/httpClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../src/httpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,UAAU,gBAAiB,GAAG,WAClC,GAAG,WACC,WAAW,OAAO,GAAG,SAAS;;;;;EAQ1C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACjB,MAAM,GAAG,IAAI,WACX,WAAW,OAAO,GAAG,SAAS,KACxC,OASF,CAAC"}
|
package/lib/httpClient.js
CHANGED
|
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
50
|
exports.getAuth0Headers = exports.httpClient = void 0;
|
|
51
|
-
var
|
|
51
|
+
var ra_core_1 = require("ra-core");
|
|
52
52
|
/**
|
|
53
53
|
* An httpClient that adds authentication headers needed by Auth0 in all requests.
|
|
54
54
|
* @param auth0Client the Auth0 client.
|
|
@@ -62,7 +62,7 @@ var httpClient = function (auth0Client) { return function (url, options) { retur
|
|
|
62
62
|
case 1:
|
|
63
63
|
token = _a.sent();
|
|
64
64
|
requestHeaders = (0, exports.getAuth0Headers)(token, options);
|
|
65
|
-
return [2 /*return*/,
|
|
65
|
+
return [2 /*return*/, ra_core_1.fetchUtils.fetchJson(url, __assign(__assign({}, options), { headers: requestHeaders }))];
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
}); }; };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ra-auth-auth0",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": "git@github.com:marmelab/ra-auth-auth0.git",
|
|
5
5
|
"author": "Anthony Rimet <anthony@marmelab.com> (https://marmelab.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,13 +16,10 @@
|
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@auth0/auth0-spa-js": "^2.0.0",
|
|
19
|
-
"ra-core": "^4.
|
|
19
|
+
"ra-core": "^4.10.0",
|
|
20
20
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
21
21
|
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0"
|
|
22
22
|
},
|
|
23
|
-
"dependencies": {
|
|
24
|
-
"react-admin": "^4.7.0"
|
|
25
|
-
},
|
|
26
23
|
"scripts": {
|
|
27
24
|
"build": "yarn run build-cjs && yarn run build-esm",
|
|
28
25
|
"build-cjs": "rimraf ./lib && tsc",
|
package/src/authProvider.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthProvider, PreviousLocationStorageKey } from '
|
|
1
|
+
import { AuthProvider, PreviousLocationStorageKey } from 'ra-core';
|
|
2
2
|
import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -25,7 +25,6 @@ import { Auth0Client } from '@auth0/auth0-spa-js';
|
|
|
25
25
|
*
|
|
26
26
|
* const authProvider = Auth0AuthProvider(clientAuth0, {
|
|
27
27
|
* loginRedirectUri: 'http://localhost:3000/auth-callback',
|
|
28
|
-
* logoutRedirectUri: 'http://localhost:3000',
|
|
29
28
|
* });
|
|
30
29
|
*
|
|
31
30
|
* const App = () => {
|
|
@@ -76,11 +75,13 @@ export const Auth0AuthProvider = (
|
|
|
76
75
|
},
|
|
77
76
|
// called when the user clicks on the logout button
|
|
78
77
|
async logout() {
|
|
79
|
-
return client
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
return client
|
|
79
|
+
.logout({
|
|
80
|
+
logoutParams: {
|
|
81
|
+
returnTo: logoutRedirectUri || window.location.origin,
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
.then(() => logoutRedirectUri || '/');
|
|
84
85
|
},
|
|
85
86
|
// called when the API returns an error
|
|
86
87
|
async checkError({ status }) {
|
|
@@ -100,7 +101,7 @@ export const Auth0AuthProvider = (
|
|
|
100
101
|
PreviousLocationStorageKey,
|
|
101
102
|
window.location.href
|
|
102
103
|
);
|
|
103
|
-
client.loginWithRedirect({
|
|
104
|
+
return client.loginWithRedirect({
|
|
104
105
|
authorizationParams: {
|
|
105
106
|
redirect_uri:
|
|
106
107
|
loginRedirectUri ??
|
|
@@ -108,6 +109,7 @@ export const Auth0AuthProvider = (
|
|
|
108
109
|
},
|
|
109
110
|
});
|
|
110
111
|
}
|
|
112
|
+
throw new Error('Unauthorized');
|
|
111
113
|
},
|
|
112
114
|
// called when the user navigates to a new location, to check for permissions / roles
|
|
113
115
|
async getPermissions() {
|
|
@@ -140,8 +142,7 @@ export const Auth0AuthProvider = (
|
|
|
140
142
|
await client.handleRedirectCallback();
|
|
141
143
|
return;
|
|
142
144
|
} catch (error) {
|
|
143
|
-
|
|
144
|
-
throw error;
|
|
145
|
+
throw { redirectTo: false, message: error.message };
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
throw new Error('Failed to handle login callback.');
|
package/src/httpClient.ts
CHANGED