studiokit-scaffolding-js 7.0.19 → 7.0.20-alpha.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.
@@ -14,6 +14,12 @@ export declare function credentialsLoginFlow(action: AuthCasV1LoginRequestAction
14
14
  export declare function casV1LoginFlow(action: AuthCasV1LoginRequestAction): SagaIterator;
15
15
  export declare function localLoginFlow(action: AuthLocalLoginRequestAction): SagaIterator;
16
16
  export declare function casTicketLoginFlow(ticket: string, service: string): SagaIterator;
17
+ /**
18
+ * When an Unauthorized 401 response is received, try to refresh the access token, otherwise trigger log out.
19
+ *
20
+ * This should be unlikely since we normally have a refresh token loop happening
21
+ * but if the app is backgrounded, the loop might not be caught up yet.
22
+ */
17
23
  export declare function handleAuthFailure(action: ModelFetchErrorAction): SagaIterator;
18
24
  export declare const getOAuthToken: TokenAccessFunction;
19
25
  export default function authSaga(clientCredentialsParam: ClientCredentials, tokenPersistenceServiceParam?: TokenPersistenceService, ticketProviderService?: TicketProviderService, codeProviderService?: CodeProviderService): SagaIterator;
@@ -279,17 +279,31 @@ function casTicketLoginFlow(ticket, service) {
279
279
  });
280
280
  }
281
281
  exports.casTicketLoginFlow = casTicketLoginFlow;
282
+ /**
283
+ * When an Unauthorized 401 response is received, try to refresh the access token, otherwise trigger log out.
284
+ *
285
+ * This should be unlikely since we normally have a refresh token loop happening
286
+ * but if the app is backgrounded, the loop might not be caught up yet.
287
+ */
282
288
  function handleAuthFailure(action) {
283
289
  return __generator(this, function (_a) {
284
290
  switch (_a.label) {
285
291
  case 0:
286
- if (!(oauthToken && action.errorData && action.errorData.status === types_1.HTTP_STATUS_CODE.UNAUTHORIZED)) return [3 /*break*/, 2];
292
+ if (!(oauthToken && action.errorData && action.errorData.status === types_1.HTTP_STATUS_CODE.UNAUTHORIZED)) return [3 /*break*/, 4];
293
+ if (!oauthToken.refresh_token) return [3 /*break*/, 2];
287
294
  logger.debug('token expired - refreshing');
288
295
  return [4 /*yield*/, effects_1.call(performTokenRefresh)];
289
296
  case 1:
290
297
  _a.sent();
291
- _a.label = 2;
292
- case 2: return [2 /*return*/];
298
+ return [3 /*break*/, 4];
299
+ case 2:
300
+ // no refresh token, trigger log out
301
+ return [4 /*yield*/, effects_1.put({ type: actions_1.AUTH_ACTION_TYPE.LOG_OUT_REQUESTED })];
302
+ case 3:
303
+ // no refresh token, trigger log out
304
+ _a.sent();
305
+ _a.label = 4;
306
+ case 4: return [2 /*return*/];
293
307
  }
294
308
  });
295
309
  }
@@ -303,17 +317,21 @@ var getOAuthToken = function (modelName) {
303
317
  if (modelName === 'getToken') {
304
318
  return [2 /*return*/, null];
305
319
  }
306
- if (!(oauthToken && oauthToken['.expires'])) return [3 /*break*/, 2];
320
+ if (!(oauthToken && oauthToken['.expires'])) return [3 /*break*/, 4];
321
+ if (!(new Date(oauthToken['.expires']) <= new Date() && !oauthToken.refresh_token)) return [3 /*break*/, 2];
322
+ return [4 /*yield*/, effects_1.put({ type: actions_1.AUTH_ACTION_TYPE.LOG_OUT_REQUESTED })];
323
+ case 1:
324
+ _a.sent();
325
+ return [2 /*return*/, null];
326
+ case 2:
307
327
  thirtySecondsFromNow = new Date();
308
328
  thirtySecondsFromNow.setSeconds(thirtySecondsFromNow.getSeconds() + 30);
309
- if (!(new Date(oauthToken['.expires']) < thirtySecondsFromNow)) return [3 /*break*/, 2];
310
- // start a token refresh and wait for the success action in case another refresh is currently happening
329
+ if (!(new Date(oauthToken['.expires']) < thirtySecondsFromNow && oauthToken.refresh_token)) return [3 /*break*/, 4];
311
330
  return [4 /*yield*/, effects_1.call(performTokenRefresh)];
312
- case 1:
313
- // start a token refresh and wait for the success action in case another refresh is currently happening
331
+ case 3:
314
332
  _a.sent();
315
333
  return [2 /*return*/, oauthToken];
316
- case 2: return [2 /*return*/, oauthToken];
334
+ case 4: return [2 /*return*/, oauthToken];
317
335
  }
318
336
  });
319
337
  };
@@ -1,3 +1,3 @@
1
- import { CallEffect } from 'redux-saga/effects';
1
+ import { CallEffect, PutEffect } from 'redux-saga/effects';
2
2
  import { OAuthTokenOrNull } from './OAuthTokenOrNull';
3
- export declare type TokenAccessFunction = (modelName: string) => IterableIterator<OAuthTokenOrNull | CallEffect>;
3
+ export declare type TokenAccessFunction = (modelName: string) => IterableIterator<OAuthTokenOrNull | CallEffect | PutEffect>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studiokit-scaffolding-js",
3
- "version": "7.0.19",
3
+ "version": "7.0.20-alpha.1",
4
4
  "description": "Common scaffolding for Studio apps at Purdue",
5
5
  "repository": "https://gitlab.com/purdue-informatics/studiokit/studiokit-scaffolding-js",
6
6
  "license": "MIT",