Added 'inactive' state handling for OAuth apps
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 34s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 34s
This commit is contained in:
parent
24107b2e82
commit
e19cf35de5
3 changed files with 55 additions and 7 deletions
|
|
@ -39,7 +39,7 @@
|
|||
"create-ba-web-app": "node ./bin/create-project.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@BridgemanAccessible/ba-auth": "^1.0.24",
|
||||
"@BridgemanAccessible/ba-auth": "^1.0.25",
|
||||
"@BridgemanAccessible/ba-logging": "^1.0.1",
|
||||
"express": "^4.19.2",
|
||||
"fs-extra": "^11.2.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { Application } from 'express';
|
||||
import axios from 'axios';
|
||||
|
||||
import { Scopes } from '@BridgemanAccessible/ba-auth';
|
||||
import Client from '@BridgemanAccessible/ba-auth/client';
|
||||
import type { OnAuthCallback } from '@BridgemanAccessible/ba-auth/client';
|
||||
|
|
@ -221,7 +222,54 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
auth_default_response_mode: this.options.auth_default_response_mode,
|
||||
client_secret: this.options.client_secret
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
// If the app is "inactive" (in a "pending" state etc...), we want to try to wait for it to become active
|
||||
// We use a progress backoff strategy to avoid hammering the server with requests
|
||||
// Because this is largely based on human intervention, exponentiation of the index by 5 (minutes), to a maximum of about 13 hours seemed reasonable
|
||||
let active = this.client.isActive();
|
||||
if(!active) {
|
||||
for(let j = 0;j < 5 && !active;j++) {
|
||||
// Sleep for:
|
||||
// 0: ! Minute
|
||||
// 1: 5 Minutes
|
||||
// 2: 25 Minutes
|
||||
// 3: 125 Minutes (~2 hours)
|
||||
// 4: 625 Minutes (~10 hours)
|
||||
// Total of ~13 hours (~780 minutes)
|
||||
logMessage(`Waiting for OAuth client to become active... (waited ${j > 0 ? 60 /* 1 minute */ * (5 ** (j - 1)) / 60 : 0} minutes so far). Now waiting for ${60 /* 1 minute */ * (5 ** (j)) / 60} minutes...`, LogLevel.WARN);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000 /* 1 second */ * 60 /* 1 minute */ + 1000 /* 1 second */ * 60 /* 1 minute */ * (5 ** j) /* Exponential backoff */));
|
||||
|
||||
await axios.get(
|
||||
`https://account.bridgemanaccessible.ca/api/v1/apps/${encodeURIComponent(baseAppUrl.toString())}/status`,
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
if(response.status === 200) {
|
||||
const data = response.data;
|
||||
|
||||
if(data.active === true) {
|
||||
logMessage('OAuth client is now active!', LogLevel.INFO);
|
||||
|
||||
active = true;
|
||||
}
|
||||
else {
|
||||
logMessage('OAuth client is still not active.', LogLevel.DEBUG);
|
||||
}
|
||||
}
|
||||
else {
|
||||
logMessage(`Received non-200 response when checking OAuth client status: ${response.status}`, LogLevel.ERROR);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
logMessage(`Error checking OAuth client status: ${error}`, LogLevel.ERROR);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.client.getSetupRoutes().forEach((route) => {
|
||||
logMessage(`Adding outside framework route: ${route}`, LogLevel.DEBUG);
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@BridgemanAccessible/ba-auth@^1.0.24":
|
||||
version "1.0.24"
|
||||
resolved "https://npm.pkg.bridgemanaccessible.ca/@BridgemanAccessible/ba-auth/-/ba-auth-1.0.24.tgz#9e60d203bad6c721c03e2e2025d73d450a103e2d"
|
||||
integrity sha512-AP6lFk+QWBIPfrVfGAe7P+m7CdpO4CWyqiE4JUmNeS3X93nnDsSvhFyfFBAMtF7XC3IuGQOwk0Y3Pj/rZmzwDw==
|
||||
"@BridgemanAccessible/ba-auth@^1.0.25":
|
||||
version "1.0.25"
|
||||
resolved "https://npm.pkg.bridgemanaccessible.ca/@BridgemanAccessible/ba-auth/-/ba-auth-1.0.25.tgz#df74fa262d0ba21a5f8980396fbdb09478db52d7"
|
||||
integrity sha512-ez2Z5TQGxHZZ/ABETt9qIsAKXbbRyj81Fpy7yY7i6OEHsyNyb2BYSXEwYjrXhfptAHqYqfbhXKVlQRv+/2tkrg==
|
||||
dependencies:
|
||||
"@BridgemanAccessible/ba-logging" "^1.0.1"
|
||||
"@azure/identity" "^4.0.1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue