@opencampus/ocid-connect-js 1.0.0 → 1.1.1
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 +202 -4
- package/dist/ocid-connect-js.js +249 -27
- package/dist/ocid-connect-js.js.map +1 -1
- package/lib/sdk/auth.js +15 -19
- package/lib/sdk/lib/CookieStorageProvider.js +50 -0
- package/lib/sdk/lib/StorageManager.js +18 -3
- package/package.json +4 -2
- package/lib/react/OCLogo.js +0 -50
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
- [Setup](#setup)
|
|
5
5
|
- [React Integration](#react-integration)
|
|
6
|
+
- [Next.js 13+ Integration](#next-js-13+-integration)
|
|
6
7
|
- [Javascript Integration](#javascript-integration)
|
|
7
8
|
- [License](#license)
|
|
8
9
|
|
|
@@ -20,6 +21,8 @@ Compile & build project
|
|
|
20
21
|
yarn build
|
|
21
22
|
```
|
|
22
23
|
|
|
24
|
+
Keep in mind that, if you are test OCID with localhost, it might not be able to run on Mobile Safari due to this limitation: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto
|
|
25
|
+
|
|
23
26
|
## React Integration
|
|
24
27
|
|
|
25
28
|
Properties that can be overriden
|
|
@@ -85,7 +88,7 @@ export default function CustomErrorComponent ()
|
|
|
85
88
|
export default function CustomLoadingComponent ()
|
|
86
89
|
{
|
|
87
90
|
return (
|
|
88
|
-
<div>
|
|
91
|
+
<div>Loading....</div>
|
|
89
92
|
);
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -122,10 +125,194 @@ const UserTokenPage = (props) => {
|
|
|
122
125
|
};
|
|
123
126
|
```
|
|
124
127
|
|
|
128
|
+
## Next Js 13+ Integration
|
|
129
|
+
|
|
130
|
+
Install dependencies
|
|
131
|
+
```bash
|
|
132
|
+
npm install @opencampus/ocid-connect-js
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
or
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
yarn add @opencampus/ocid-connect-js
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 1. Create a wrapper component
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
components/OCConnectWrapper.jsx
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
'use client'
|
|
149
|
+
|
|
150
|
+
import { ReactNode } from 'react';
|
|
151
|
+
import { OCConnect, OCConnectProps } from '@opencampus/ocid-connect-js';
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
export default function OCConnectWrapper({ children, opts, sandboxMode }) {
|
|
156
|
+
return (
|
|
157
|
+
<OCConnect opts={opts} sandboxMode={sandboxMode}>
|
|
158
|
+
{children}
|
|
159
|
+
</OCConnect>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### 2. Update the root layout
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
app/layout.jsx
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
import OCConnectWrapper from '../components/OCConnectWrapper';
|
|
173
|
+
|
|
174
|
+
export default function RootLayout({
|
|
175
|
+
children,
|
|
176
|
+
}) {
|
|
177
|
+
const opts = {
|
|
178
|
+
redirectUri: 'http://localhost:3000/redirect', // Adjust this URL
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<html lang="en">
|
|
183
|
+
<body>
|
|
184
|
+
<OCConnectWrapper opts={opts} sandboxMode={true}>
|
|
185
|
+
{children}
|
|
186
|
+
</OCConnectWrapper>
|
|
187
|
+
</body>
|
|
188
|
+
</html>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 3. Create a redirect page
|
|
194
|
+
|
|
195
|
+
```
|
|
196
|
+
app/redirect/page.jsx
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
'use client'
|
|
201
|
+
|
|
202
|
+
import { LoginCallBack } from '@opencampus/ocid-connect-js';
|
|
203
|
+
import { useRouter } from 'next/navigation';
|
|
204
|
+
|
|
205
|
+
export default function RedirectPage() {
|
|
206
|
+
const router = useRouter();
|
|
207
|
+
|
|
208
|
+
const loginSuccess = () => {
|
|
209
|
+
router.push('/'); // Redirect after successful login
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const loginError = (error) => {
|
|
213
|
+
console.error('Login error:', error);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
function CustomErrorComponent() {
|
|
217
|
+
const { authState } = useOCAuth();
|
|
218
|
+
return <div>Error Logging in: {authState.error?.message}</div>;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function CustomLoadingComponent() {
|
|
222
|
+
return <div>Loading....</div>;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<LoginCallBack
|
|
227
|
+
errorCallback={loginError}
|
|
228
|
+
successCallback={loginSuccess}
|
|
229
|
+
customErrorComponent={<CustomErrorComponent />}
|
|
230
|
+
customLoadingComponent={<CustomLoadingComponent />}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
### 4. Create a LoginButton Component
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
components/LoginButton.jsx
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
'use client'
|
|
246
|
+
|
|
247
|
+
import { useOCAuth } from '@opencampus/ocid-connect-js';
|
|
248
|
+
|
|
249
|
+
export default function LoginButton() {
|
|
250
|
+
const { ocAuth } = useOCAuth();
|
|
251
|
+
|
|
252
|
+
const handleLogin = async () => {
|
|
253
|
+
try {
|
|
254
|
+
await ocAuth.signInWithRedirect({ state: 'opencampus' });
|
|
255
|
+
} catch (error) {
|
|
256
|
+
console.error('Login error:', error);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
return <button onClick={handleLogin}>Login</button>;
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 5. Use Components in Your Page
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
app/page.jsx
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
|
|
272
|
+
'use client';
|
|
273
|
+
|
|
274
|
+
import { useEffect } from 'react';
|
|
275
|
+
import LoginButton from '../components/LoginButton';
|
|
276
|
+
import { useOCAuth } from '@opencampus/ocid-connect-js';
|
|
277
|
+
|
|
278
|
+
export default function Home() {
|
|
279
|
+
const { authState, ocAuth } = useOCAuth();
|
|
280
|
+
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
console.log(authState);
|
|
283
|
+
}, [authState]); // Now it will log whenever authState changes
|
|
284
|
+
|
|
285
|
+
if (authState.error) {
|
|
286
|
+
return <div>Error: {authState.error.message}</div>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Add a loading state
|
|
290
|
+
if (authState.isLoading) {
|
|
291
|
+
return <div>Loading...</div>;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return (
|
|
295
|
+
<div>
|
|
296
|
+
<h1>Welcome to My App</h1>
|
|
297
|
+
{authState.isAuthenticated ? (
|
|
298
|
+
<p>You are logged in! {JSON.stringify(ocAuth.getAuthInfo())}</p>
|
|
299
|
+
|
|
300
|
+
) : (
|
|
301
|
+
<LoginButton />
|
|
302
|
+
)}
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
```
|
|
308
|
+
|
|
125
309
|
|
|
126
310
|
## Javascript Integration
|
|
311
|
+
If React is not desirable front end framework, Our sdk could be used to integrate seamlessly with others.
|
|
312
|
+
|
|
313
|
+
Our authentication flow adhere to OIDC Auth Code Flow + PKCE standard.
|
|
127
314
|
|
|
128
|
-
|
|
315
|
+
First and foremost, we could initialize the SDK to use either OCAuthSandbox (testing environment) and OCAuthLive (production environment)
|
|
129
316
|
|
|
130
317
|
```js
|
|
131
318
|
import { OCAuthSandbox } from '@opencampus/ocid-connect-js';
|
|
@@ -136,7 +323,7 @@ Main Methods of Auth SDK
|
|
|
136
323
|
|
|
137
324
|
| Method | Description |
|
|
138
325
|
| --- | --- |
|
|
139
|
-
| signInWithRedirect | Initialize
|
|
326
|
+
| signInWithRedirect | Initialize login process. Accept "state" as an input |
|
|
140
327
|
| handleLoginRedirect | Return the auth state of the login process |
|
|
141
328
|
| getAuthInfo | Return auth object { edu_username, eth_address } |
|
|
142
329
|
| getAuthState | Return auth state data { accessToken, idToken, isAuthenticated } |
|
|
@@ -152,6 +339,17 @@ await authSdk.signInWithRedirect( {
|
|
|
152
339
|
});
|
|
153
340
|
```
|
|
154
341
|
|
|
342
|
+
The login flow adhere with PKCE standard. The following params will be prepared by our SDK and send to authentication server.
|
|
343
|
+
|
|
344
|
+
| Method | Description |
|
|
345
|
+
| --- | --- |
|
|
346
|
+
| origin_url | Origin of the authentication request |
|
|
347
|
+
| redirect_uri | Desitnation after the authentication is completed |
|
|
348
|
+
| response_type | 'code' is being used to adhere with PKCE standard |
|
|
349
|
+
| scope | only support 'openid' at the moment |
|
|
350
|
+
| code_challenge | adhere with PKCE standard |
|
|
351
|
+
| code_challenge_method | Only S256 is supported at the moment |
|
|
352
|
+
|
|
155
353
|
Sample usage to handle login response
|
|
156
354
|
|
|
157
355
|
```js
|
|
@@ -168,4 +366,4 @@ try {
|
|
|
168
366
|
```
|
|
169
367
|
|
|
170
368
|
### License
|
|
171
|
-
ocid-connect-js is released under the MIT license.
|
|
369
|
+
ocid-connect-js is released under the MIT license.
|
package/dist/ocid-connect-js.js
CHANGED
|
@@ -111,7 +111,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
111
111
|
|
|
112
112
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useOCAuth", function() { return _react__WEBPACK_IMPORTED_MODULE_0__["useOCAuth"]; });
|
|
113
113
|
|
|
114
|
-
/* harmony import */ var _sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
114
|
+
/* harmony import */ var _sdk__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(27);
|
|
115
115
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TokenManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["TokenManager"]; });
|
|
116
116
|
|
|
117
117
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransactionManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["TransactionManager"]; });
|
|
@@ -120,6 +120,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
120
120
|
|
|
121
121
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["LocalStorageManager"]; });
|
|
122
122
|
|
|
123
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["getStorageClass"]; });
|
|
124
|
+
|
|
123
125
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthCore", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["OCAuthCore"]; });
|
|
124
126
|
|
|
125
127
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthLive", function() { return _sdk__WEBPACK_IMPORTED_MODULE_1__["OCAuthLive"]; });
|
|
@@ -503,7 +505,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
503
505
|
/* harmony import */ var _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
|
|
504
506
|
/* harmony import */ var _lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(22);
|
|
505
507
|
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(10);
|
|
506
|
-
/* harmony import */ var _endpoints__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
|
|
508
|
+
/* harmony import */ var _endpoints__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(25);
|
|
507
509
|
/* harmony import */ var _utils_errors__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(18);
|
|
508
510
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
509
511
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
@@ -556,7 +558,7 @@ var OCAuthCore = /*#__PURE__*/function () {
|
|
|
556
558
|
return _createClass(OCAuthCore, [{
|
|
557
559
|
key: "clearStorage",
|
|
558
560
|
value: function clearStorage() {
|
|
559
|
-
this.transactionManager.
|
|
561
|
+
this.transactionManager.clear();
|
|
560
562
|
this.tokenManager.clear();
|
|
561
563
|
}
|
|
562
564
|
}, {
|
|
@@ -680,19 +682,9 @@ var OCAuthCore = /*#__PURE__*/function () {
|
|
|
680
682
|
}
|
|
681
683
|
}]);
|
|
682
684
|
}();
|
|
683
|
-
var OCAuthLS = /*#__PURE__*/function (_OCAuthCore2) {
|
|
684
|
-
function OCAuthLS(loginEndPoint, tokenEndpoint, redirectUri, publicKey) {
|
|
685
|
-
_classCallCheck(this, OCAuthLS);
|
|
686
|
-
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["LocalStorageManager"]);
|
|
687
|
-
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["LocalStorageManager"], tokenEndpoint, publicKey);
|
|
688
|
-
return _callSuper(this, OCAuthLS, [loginEndPoint, redirectUri, pkceTransactionManager, tokenManager]);
|
|
689
|
-
}
|
|
690
|
-
_inherits(OCAuthLS, _OCAuthCore2);
|
|
691
|
-
return _createClass(OCAuthLS);
|
|
692
|
-
}(OCAuthCore);
|
|
693
685
|
var LIVE_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBIDHtLbgVM76SXZ4iuIjuO+ERQPnVpJzagOsZdYxFG3ZJmvfdpr/Z29SLUbdZWafrOlAVlKe1Ovf/tcH671tTw==';
|
|
694
686
|
var SANDBOX_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE/EymMLXd/MVYPK5r2xXQj91ZVvX3OQ+QagvR2N6lCvRVjnzmOtPRTf+u5g1RliWnmuxbV3gTm0/0VuV/40Salg==';
|
|
695
|
-
var OCAuthLive = /*#__PURE__*/function (
|
|
687
|
+
var OCAuthLive = /*#__PURE__*/function (_OCAuthCore2) {
|
|
696
688
|
function OCAuthLive() {
|
|
697
689
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
698
690
|
_classCallCheck(this, OCAuthLive);
|
|
@@ -703,12 +695,15 @@ var OCAuthLive = /*#__PURE__*/function (_OCAuthLS) {
|
|
|
703
695
|
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.opencampus.xyz/auth/token';
|
|
704
696
|
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.opencampus.xyz/auth/login';
|
|
705
697
|
var publicKey = overridePublicKey || LIVE_PUBLIC_KEY;
|
|
706
|
-
|
|
698
|
+
var storageClass = Object(_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["getStorageClass"])(opts);
|
|
699
|
+
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](storageClass);
|
|
700
|
+
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](storageClass, tokenEndpoint, publicKey);
|
|
701
|
+
return _callSuper(this, OCAuthLive, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager]);
|
|
707
702
|
}
|
|
708
|
-
_inherits(OCAuthLive,
|
|
703
|
+
_inherits(OCAuthLive, _OCAuthCore2);
|
|
709
704
|
return _createClass(OCAuthLive);
|
|
710
|
-
}(
|
|
711
|
-
var OCAuthSandbox = /*#__PURE__*/function (
|
|
705
|
+
}(OCAuthCore);
|
|
706
|
+
var OCAuthSandbox = /*#__PURE__*/function (_OCAuthCore3) {
|
|
712
707
|
function OCAuthSandbox() {
|
|
713
708
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
714
709
|
_classCallCheck(this, OCAuthSandbox);
|
|
@@ -719,11 +714,14 @@ var OCAuthSandbox = /*#__PURE__*/function (_OCAuthLS2) {
|
|
|
719
714
|
var tokenEndpoint = overrideTokenEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/token';
|
|
720
715
|
var loginEndpoint = overrideLoginEndpoint || 'https://api.login.sandbox.opencampus.xyz/auth/login';
|
|
721
716
|
var publicKey = overridePublicKey || SANDBOX_PUBLIC_KEY;
|
|
722
|
-
|
|
717
|
+
var storageClass = Object(_lib_StorageManager__WEBPACK_IMPORTED_MODULE_3__["getStorageClass"])(opts);
|
|
718
|
+
var pkceTransactionManager = new _lib_TransactionManager__WEBPACK_IMPORTED_MODULE_2__["default"](storageClass);
|
|
719
|
+
var tokenManager = new _lib_TokenManager__WEBPACK_IMPORTED_MODULE_1__["default"](storageClass, tokenEndpoint, publicKey);
|
|
720
|
+
return _callSuper(this, OCAuthSandbox, [loginEndpoint, redirectUri, pkceTransactionManager, tokenManager]);
|
|
723
721
|
}
|
|
724
|
-
_inherits(OCAuthSandbox,
|
|
722
|
+
_inherits(OCAuthSandbox, _OCAuthCore3);
|
|
725
723
|
return _createClass(OCAuthSandbox);
|
|
726
|
-
}(
|
|
724
|
+
}(OCAuthCore);
|
|
727
725
|
|
|
728
726
|
/***/ }),
|
|
729
727
|
/* 8 */
|
|
@@ -1515,7 +1513,9 @@ var TransactionManager = /*#__PURE__*/function () {
|
|
|
1515
1513
|
__webpack_require__.r(__webpack_exports__);
|
|
1516
1514
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BaseStorageManager", function() { return BaseStorageManager; });
|
|
1517
1515
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return LocalStorageManager; });
|
|
1516
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return getStorageClass; });
|
|
1518
1517
|
/* harmony import */ var _utils_errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
|
|
1518
|
+
/* harmony import */ var _CookieStorageProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(23);
|
|
1519
1519
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1520
1520
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
1521
1521
|
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
@@ -1542,7 +1542,6 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
1542
1542
|
|
|
1543
1543
|
|
|
1544
1544
|
|
|
1545
|
-
// We only support local storage for now
|
|
1546
1545
|
var SavedObject = /*#__PURE__*/function () {
|
|
1547
1546
|
function SavedObject(storageProvider, storageName) {
|
|
1548
1547
|
_classCallCheck(this, SavedObject);
|
|
@@ -1631,6 +1630,21 @@ var LocalStorageManager = /*#__PURE__*/function (_BaseStorageManager2) {
|
|
|
1631
1630
|
_inherits(LocalStorageManager, _BaseStorageManager2);
|
|
1632
1631
|
return _createClass(LocalStorageManager);
|
|
1633
1632
|
}(BaseStorageManager);
|
|
1633
|
+
var getStorageClass = function getStorageClass(opts) {
|
|
1634
|
+
// Only cookie support domain based storage
|
|
1635
|
+
if (opts.storageType === 'cookie') {
|
|
1636
|
+
return /*#__PURE__*/function (_BaseStorageManager3) {
|
|
1637
|
+
function CookieStorageManager(storageName) {
|
|
1638
|
+
_classCallCheck(this, CookieStorageManager);
|
|
1639
|
+
return _callSuper(this, CookieStorageManager, [storageName, new _CookieStorageProvider__WEBPACK_IMPORTED_MODULE_1__["CookieStorageProvider"](opts.cookieDomain)]);
|
|
1640
|
+
}
|
|
1641
|
+
_inherits(CookieStorageManager, _BaseStorageManager3);
|
|
1642
|
+
return _createClass(CookieStorageManager);
|
|
1643
|
+
}(BaseStorageManager);
|
|
1644
|
+
} else {
|
|
1645
|
+
return LocalStorageManager;
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1634
1648
|
|
|
1635
1649
|
/***/ }),
|
|
1636
1650
|
/* 23 */
|
|
@@ -1638,7 +1652,211 @@ var LocalStorageManager = /*#__PURE__*/function (_BaseStorageManager2) {
|
|
|
1638
1652
|
|
|
1639
1653
|
"use strict";
|
|
1640
1654
|
__webpack_require__.r(__webpack_exports__);
|
|
1641
|
-
/* harmony
|
|
1655
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CookieStorageProvider", function() { return CookieStorageProvider; });
|
|
1656
|
+
/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24);
|
|
1657
|
+
/* harmony import */ var js_cookie__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(js_cookie__WEBPACK_IMPORTED_MODULE_0__);
|
|
1658
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
1659
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
1660
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
1661
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
1662
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
1663
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
1664
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1665
|
+
/*!
|
|
1666
|
+
* Copyright 2024-Present Animoca Brands Corporation Ltd.
|
|
1667
|
+
*
|
|
1668
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
1669
|
+
*
|
|
1670
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
1671
|
+
*
|
|
1672
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
1673
|
+
*/
|
|
1674
|
+
|
|
1675
|
+
|
|
1676
|
+
|
|
1677
|
+
// Wrapper to support Cookie based storage
|
|
1678
|
+
var CookieStorageProvider = /*#__PURE__*/function () {
|
|
1679
|
+
function CookieStorageProvider(domain) {
|
|
1680
|
+
_classCallCheck(this, CookieStorageProvider);
|
|
1681
|
+
_defineProperty(this, "domain", void 0);
|
|
1682
|
+
this.domain = domain;
|
|
1683
|
+
}
|
|
1684
|
+
return _createClass(CookieStorageProvider, [{
|
|
1685
|
+
key: "getItem",
|
|
1686
|
+
value: function getItem(key) {
|
|
1687
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.get(key);
|
|
1688
|
+
}
|
|
1689
|
+
}, {
|
|
1690
|
+
key: "setItem",
|
|
1691
|
+
value: function setItem(key, value) {
|
|
1692
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.set(key, value, {
|
|
1693
|
+
expires: 365,
|
|
1694
|
+
domain: this.domain
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
}, {
|
|
1698
|
+
key: "removeItem",
|
|
1699
|
+
value: function removeItem(key) {
|
|
1700
|
+
return js_cookie__WEBPACK_IMPORTED_MODULE_0___default.a.remove(key);
|
|
1701
|
+
}
|
|
1702
|
+
}]);
|
|
1703
|
+
}();
|
|
1704
|
+
|
|
1705
|
+
/***/ }),
|
|
1706
|
+
/* 24 */
|
|
1707
|
+
/***/ (function(module, exports, __webpack_require__) {
|
|
1708
|
+
|
|
1709
|
+
/*! js-cookie v3.0.5 | MIT */
|
|
1710
|
+
;
|
|
1711
|
+
(function (global, factory) {
|
|
1712
|
+
true ? module.exports = factory() :
|
|
1713
|
+
undefined;
|
|
1714
|
+
})(this, (function () { 'use strict';
|
|
1715
|
+
|
|
1716
|
+
/* eslint-disable no-var */
|
|
1717
|
+
function assign (target) {
|
|
1718
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1719
|
+
var source = arguments[i];
|
|
1720
|
+
for (var key in source) {
|
|
1721
|
+
target[key] = source[key];
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return target
|
|
1725
|
+
}
|
|
1726
|
+
/* eslint-enable no-var */
|
|
1727
|
+
|
|
1728
|
+
/* eslint-disable no-var */
|
|
1729
|
+
var defaultConverter = {
|
|
1730
|
+
read: function (value) {
|
|
1731
|
+
if (value[0] === '"') {
|
|
1732
|
+
value = value.slice(1, -1);
|
|
1733
|
+
}
|
|
1734
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent)
|
|
1735
|
+
},
|
|
1736
|
+
write: function (value) {
|
|
1737
|
+
return encodeURIComponent(value).replace(
|
|
1738
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
1739
|
+
decodeURIComponent
|
|
1740
|
+
)
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
/* eslint-enable no-var */
|
|
1744
|
+
|
|
1745
|
+
/* eslint-disable no-var */
|
|
1746
|
+
|
|
1747
|
+
function init (converter, defaultAttributes) {
|
|
1748
|
+
function set (name, value, attributes) {
|
|
1749
|
+
if (typeof document === 'undefined') {
|
|
1750
|
+
return
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
1754
|
+
|
|
1755
|
+
if (typeof attributes.expires === 'number') {
|
|
1756
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
1757
|
+
}
|
|
1758
|
+
if (attributes.expires) {
|
|
1759
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
name = encodeURIComponent(name)
|
|
1763
|
+
.replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)
|
|
1764
|
+
.replace(/[()]/g, escape);
|
|
1765
|
+
|
|
1766
|
+
var stringifiedAttributes = '';
|
|
1767
|
+
for (var attributeName in attributes) {
|
|
1768
|
+
if (!attributes[attributeName]) {
|
|
1769
|
+
continue
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
stringifiedAttributes += '; ' + attributeName;
|
|
1773
|
+
|
|
1774
|
+
if (attributes[attributeName] === true) {
|
|
1775
|
+
continue
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1778
|
+
// Considers RFC 6265 section 5.2:
|
|
1779
|
+
// ...
|
|
1780
|
+
// 3. If the remaining unparsed-attributes contains a %x3B (";")
|
|
1781
|
+
// character:
|
|
1782
|
+
// Consume the characters of the unparsed-attributes up to,
|
|
1783
|
+
// not including, the first %x3B (";") character.
|
|
1784
|
+
// ...
|
|
1785
|
+
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
return (document.cookie =
|
|
1789
|
+
name + '=' + converter.write(value, name) + stringifiedAttributes)
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
function get (name) {
|
|
1793
|
+
if (typeof document === 'undefined' || (arguments.length && !name)) {
|
|
1794
|
+
return
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// To prevent the for loop in the first place assign an empty array
|
|
1798
|
+
// in case there are no cookies at all.
|
|
1799
|
+
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
|
1800
|
+
var jar = {};
|
|
1801
|
+
for (var i = 0; i < cookies.length; i++) {
|
|
1802
|
+
var parts = cookies[i].split('=');
|
|
1803
|
+
var value = parts.slice(1).join('=');
|
|
1804
|
+
|
|
1805
|
+
try {
|
|
1806
|
+
var found = decodeURIComponent(parts[0]);
|
|
1807
|
+
jar[found] = converter.read(value, found);
|
|
1808
|
+
|
|
1809
|
+
if (name === found) {
|
|
1810
|
+
break
|
|
1811
|
+
}
|
|
1812
|
+
} catch (e) {}
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
return name ? jar[name] : jar
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
return Object.create(
|
|
1819
|
+
{
|
|
1820
|
+
set,
|
|
1821
|
+
get,
|
|
1822
|
+
remove: function (name, attributes) {
|
|
1823
|
+
set(
|
|
1824
|
+
name,
|
|
1825
|
+
'',
|
|
1826
|
+
assign({}, attributes, {
|
|
1827
|
+
expires: -1
|
|
1828
|
+
})
|
|
1829
|
+
);
|
|
1830
|
+
},
|
|
1831
|
+
withAttributes: function (attributes) {
|
|
1832
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
1833
|
+
},
|
|
1834
|
+
withConverter: function (converter) {
|
|
1835
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
1836
|
+
}
|
|
1837
|
+
},
|
|
1838
|
+
{
|
|
1839
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
1840
|
+
converter: { value: Object.freeze(converter) }
|
|
1841
|
+
}
|
|
1842
|
+
)
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
var api = init(defaultConverter, { path: '/' });
|
|
1846
|
+
/* eslint-enable no-var */
|
|
1847
|
+
|
|
1848
|
+
return api;
|
|
1849
|
+
|
|
1850
|
+
}));
|
|
1851
|
+
|
|
1852
|
+
|
|
1853
|
+
/***/ }),
|
|
1854
|
+
/* 25 */
|
|
1855
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1856
|
+
|
|
1857
|
+
"use strict";
|
|
1858
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1859
|
+
/* harmony import */ var _buildAuthEndpointUrl__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26);
|
|
1642
1860
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "buildAuthEndpointUrl", function() { return _buildAuthEndpointUrl__WEBPACK_IMPORTED_MODULE_0__["buildAuthEndpointUrl"]; });
|
|
1643
1861
|
|
|
1644
1862
|
/*!
|
|
@@ -1653,7 +1871,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1653
1871
|
|
|
1654
1872
|
|
|
1655
1873
|
/***/ }),
|
|
1656
|
-
/*
|
|
1874
|
+
/* 26 */
|
|
1657
1875
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1658
1876
|
|
|
1659
1877
|
"use strict";
|
|
@@ -1687,12 +1905,12 @@ var buildAuthEndpointUrl = function buildAuthEndpointUrl(signInParams, loginEndP
|
|
|
1687
1905
|
};
|
|
1688
1906
|
|
|
1689
1907
|
/***/ }),
|
|
1690
|
-
/*
|
|
1908
|
+
/* 27 */
|
|
1691
1909
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1692
1910
|
|
|
1693
1911
|
"use strict";
|
|
1694
1912
|
__webpack_require__.r(__webpack_exports__);
|
|
1695
|
-
/* harmony import */ var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
1913
|
+
/* harmony import */ var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(28);
|
|
1696
1914
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TokenManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["TokenManager"]; });
|
|
1697
1915
|
|
|
1698
1916
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TransactionManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["TransactionManager"]; });
|
|
@@ -1701,6 +1919,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1701
1919
|
|
|
1702
1920
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["LocalStorageManager"]; });
|
|
1703
1921
|
|
|
1922
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["getStorageClass"]; });
|
|
1923
|
+
|
|
1704
1924
|
/* harmony import */ var _auth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
|
|
1705
1925
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OCAuthCore", function() { return _auth__WEBPACK_IMPORTED_MODULE_1__["OCAuthCore"]; });
|
|
1706
1926
|
|
|
@@ -1712,7 +1932,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1712
1932
|
|
|
1713
1933
|
|
|
1714
1934
|
/***/ }),
|
|
1715
|
-
/*
|
|
1935
|
+
/* 28 */
|
|
1716
1936
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1717
1937
|
|
|
1718
1938
|
"use strict";
|
|
@@ -1728,6 +1948,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1728
1948
|
|
|
1729
1949
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "LocalStorageManager", function() { return _StorageManager__WEBPACK_IMPORTED_MODULE_2__["LocalStorageManager"]; });
|
|
1730
1950
|
|
|
1951
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getStorageClass", function() { return _StorageManager__WEBPACK_IMPORTED_MODULE_2__["getStorageClass"]; });
|
|
1952
|
+
|
|
1731
1953
|
|
|
1732
1954
|
|
|
1733
1955
|
|