@opencampus/ocid-connect-js 1.2.2 → 1.2.5
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/README.md +9 -7
- package/dist/ocid-connect-js.js +33 -21
- package/dist/ocid-connect-js.js.map +1 -1
- package/lib/react/LoginCallBack.js +2 -1
- package/lib/react/OCConnect.js +12 -8
- package/lib/sdk/auth.js +15 -11
- package/lib/sdk/lib/AuthInfoManager.js +4 -1
- package/package.json +1 -1
|
@@ -27,6 +27,7 @@ var LoginCallBack = function LoginCallBack(_ref) {
|
|
|
27
27
|
customErrorComponent = _ref.customErrorComponent,
|
|
28
28
|
customLoadingComponent = _ref.customLoadingComponent;
|
|
29
29
|
var _useOCAuth = (0, _OCContext.useOCAuth)(),
|
|
30
|
+
isInitialized = _useOCAuth.isInitialized,
|
|
30
31
|
ocAuth = _useOCAuth.ocAuth,
|
|
31
32
|
authState = _useOCAuth.authState,
|
|
32
33
|
setAuthError = _useOCAuth.setAuthError;
|
|
@@ -68,7 +69,7 @@ var LoginCallBack = function LoginCallBack(_ref) {
|
|
|
68
69
|
handleLogin();
|
|
69
70
|
}
|
|
70
71
|
}, [ocAuth]);
|
|
71
|
-
if (authState.error !== undefined && !errorCallback) {
|
|
72
|
+
if (isInitialized && authState.error !== undefined && !errorCallback) {
|
|
72
73
|
return customErrorComponent ? customErrorComponent : /*#__PURE__*/_react["default"].createElement("div", null, "Error Logging in: ", authState.error.message);
|
|
73
74
|
} else {
|
|
74
75
|
return customLoadingComponent ? customLoadingComponent : /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("h3", null, "Loading ......"));
|
package/lib/react/OCConnect.js
CHANGED
|
@@ -28,7 +28,7 @@ var OCConnect = function OCConnect(_ref) {
|
|
|
28
28
|
var children = _ref.children,
|
|
29
29
|
opts = _ref.opts,
|
|
30
30
|
sandboxMode = _ref.sandboxMode;
|
|
31
|
-
var _useState = (0, _react.useState)(
|
|
31
|
+
var _useState = (0, _react.useState)(),
|
|
32
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
33
33
|
ocAuth = _useState2[0],
|
|
34
34
|
setOcAuth = _useState2[1];
|
|
@@ -40,16 +40,18 @@ var OCConnect = function OCConnect(_ref) {
|
|
|
40
40
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
41
|
ethAddress = _useState6[0],
|
|
42
42
|
setEthAddress = _useState6[1];
|
|
43
|
-
var _useState7 = (0, _react.useState)(
|
|
44
|
-
isAuthenticated: false
|
|
45
|
-
}),
|
|
43
|
+
var _useState7 = (0, _react.useState)(),
|
|
46
44
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
47
45
|
authState = _useState8[0],
|
|
48
46
|
setAuthState = _useState8[1];
|
|
49
|
-
var _useState9 = (0, _react.useState)(
|
|
47
|
+
var _useState9 = (0, _react.useState)(false),
|
|
50
48
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
isInitialized = _useState10[0],
|
|
50
|
+
setIsInitialized = _useState10[1];
|
|
51
|
+
var _useState11 = (0, _react.useState)(null),
|
|
52
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
53
|
+
authError = _useState12[0],
|
|
54
|
+
setAuthError = _useState12[1];
|
|
53
55
|
var updateAuthState = function updateAuthState(authState) {
|
|
54
56
|
setAuthState(authState);
|
|
55
57
|
setOCId(authState.OCId);
|
|
@@ -61,9 +63,10 @@ var OCConnect = function OCConnect(_ref) {
|
|
|
61
63
|
var authSdk = sandboxMode ? new _auth.OCAuthSandbox(opts) : new _auth.OCAuthLive(opts);
|
|
62
64
|
updateAuthState(authSdk.getAuthState());
|
|
63
65
|
setOcAuth(authSdk);
|
|
66
|
+
setIsInitialized(true);
|
|
64
67
|
}, []);
|
|
65
68
|
(0, _react.useEffect)(function () {
|
|
66
|
-
if (ocAuth.authInfoManager) {
|
|
69
|
+
if (ocAuth && ocAuth.authInfoManager) {
|
|
67
70
|
// reactively recieve update on the authstate change
|
|
68
71
|
ocAuth.authInfoManager.subscribe(updateAuthState);
|
|
69
72
|
return function () {
|
|
@@ -78,6 +81,7 @@ var OCConnect = function OCConnect(_ref) {
|
|
|
78
81
|
ocAuth: ocAuth,
|
|
79
82
|
authState: authState,
|
|
80
83
|
authError: authError,
|
|
84
|
+
isInitialized: isInitialized,
|
|
81
85
|
setAuthError: setAuthError
|
|
82
86
|
}
|
|
83
87
|
}, children);
|
package/lib/sdk/auth.js
CHANGED
|
@@ -65,21 +65,24 @@ var OCAuthCore = exports.OCAuthCore = /*#__PURE__*/function () {
|
|
|
65
65
|
}, {
|
|
66
66
|
key: "logout",
|
|
67
67
|
value: function () {
|
|
68
|
-
var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
69
|
-
var
|
|
68
|
+
var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(logoutReturnTo) {
|
|
69
|
+
var url;
|
|
70
70
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
71
71
|
while (1) switch (_context.prev = _context.next) {
|
|
72
72
|
case 0:
|
|
73
73
|
this.clearStorage();
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
url = new URL(this.logoutEndPoint);
|
|
75
|
+
if (logoutReturnTo) {
|
|
76
|
+
url.searchParams.append('returnTo', logoutReturnTo);
|
|
77
|
+
}
|
|
78
|
+
window.location.assign(url.toString());
|
|
79
|
+
case 4:
|
|
77
80
|
case "end":
|
|
78
81
|
return _context.stop();
|
|
79
82
|
}
|
|
80
83
|
}, _callee, this);
|
|
81
84
|
}));
|
|
82
|
-
function logout() {
|
|
85
|
+
function logout(_x) {
|
|
83
86
|
return _logout.apply(this, arguments);
|
|
84
87
|
}
|
|
85
88
|
return logout;
|
|
@@ -111,7 +114,7 @@ var OCAuthCore = exports.OCAuthCore = /*#__PURE__*/function () {
|
|
|
111
114
|
}
|
|
112
115
|
}, _callee2, this);
|
|
113
116
|
}));
|
|
114
|
-
function signInWithRedirect(
|
|
117
|
+
function signInWithRedirect(_x2) {
|
|
115
118
|
return _signInWithRedirect.apply(this, arguments);
|
|
116
119
|
}
|
|
117
120
|
return signInWithRedirect;
|
|
@@ -172,7 +175,7 @@ var OCAuthCore = exports.OCAuthCore = /*#__PURE__*/function () {
|
|
|
172
175
|
var _this$getParsedIdToke = this.getParsedIdToken(),
|
|
173
176
|
edu_username = _this$getParsedIdToke.edu_username,
|
|
174
177
|
eth_address = _this$getParsedIdToke.eth_address;
|
|
175
|
-
this.authInfoManager.setAuthState(this.getAccessToken(), this.getIdToken(), edu_username, eth_address,
|
|
178
|
+
this.authInfoManager.setAuthState(this.getAccessToken(), this.getIdToken(), edu_username, eth_address, true);
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
}, {
|
|
@@ -250,7 +253,7 @@ var OCAuthLive = exports.OCAuthLive = /*#__PURE__*/function (_OCAuthCore2) {
|
|
|
250
253
|
var storageClass = (0, _StorageManager.getStorageClass)(opts);
|
|
251
254
|
var pkceTransactionManager = new _TransactionManager["default"](storageClass);
|
|
252
255
|
var tokenManager = new _TokenManager["default"](storageClass, tokenEndpoint, publicKey);
|
|
253
|
-
return _callSuper(this, OCAuthLive, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode, logoutEndpoint]);
|
|
256
|
+
return _callSuper(this, OCAuthLive, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode, logoutEndpoint, false]);
|
|
254
257
|
}
|
|
255
258
|
_inherits(OCAuthLive, _OCAuthCore2);
|
|
256
259
|
return _createClass(OCAuthLive);
|
|
@@ -264,7 +267,8 @@ var OCAuthSandbox = exports.OCAuthSandbox = /*#__PURE__*/function (_OCAuthCore3)
|
|
|
264
267
|
overrideLogoutEndpoint = opts.logoutEndPoint,
|
|
265
268
|
overridePublicKey = opts.publicKey,
|
|
266
269
|
redirectUri = opts.redirectUri,
|
|
267
|
-
referralCode = opts.referralCode
|
|
270
|
+
referralCode = opts.referralCode,
|
|
271
|
+
mode = opts.mode;
|
|
268
272
|
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/token';
|
|
269
273
|
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/login';
|
|
270
274
|
var logoutEndpoint = overrideLogoutEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/logout';
|
|
@@ -272,7 +276,7 @@ var OCAuthSandbox = exports.OCAuthSandbox = /*#__PURE__*/function (_OCAuthCore3)
|
|
|
272
276
|
var storageClass = (0, _StorageManager.getStorageClass)(opts);
|
|
273
277
|
var pkceTransactionManager = new _TransactionManager["default"](storageClass);
|
|
274
278
|
var tokenManager = new _TokenManager["default"](storageClass, tokenEndpoint, publicKey);
|
|
275
|
-
return _callSuper(this, OCAuthSandbox, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode, logoutEndpoint]);
|
|
279
|
+
return _callSuper(this, OCAuthSandbox, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager, referralCode, logoutEndpoint, true]);
|
|
276
280
|
}
|
|
277
281
|
_inherits(OCAuthSandbox, _OCAuthCore3);
|
|
278
282
|
return _createClass(OCAuthSandbox);
|
|
@@ -50,7 +50,10 @@ var AuthInfoManager = /*#__PURE__*/function () {
|
|
|
50
50
|
}, {
|
|
51
51
|
key: "clear",
|
|
52
52
|
value: function clear() {
|
|
53
|
-
this._authState =
|
|
53
|
+
this._authState = {
|
|
54
|
+
isAuthenticated: false
|
|
55
|
+
};
|
|
56
|
+
this._emitter.emit(EVENT_AUTH_STATE_CHANGE, this._authState);
|
|
54
57
|
}
|
|
55
58
|
}, {
|
|
56
59
|
key: "subscribe",
|