Made needed changes for adapter architecture + added HealthCheckableRequestClient that checks service health before sending request
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 30s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 30s
This commit is contained in:
parent
38cd098cab
commit
6ac9c2518f
5 changed files with 165 additions and 8 deletions
|
|
@ -3,12 +3,14 @@ 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';
|
||||
import { BaseKeystore } from '@BridgemanAccessible/ba-auth_keystore';
|
||||
import { logMessage, LogLevel } from '@BridgemanAccessible/ba-logging';
|
||||
|
||||
import { App } from '../App.js';
|
||||
import { Initializer } from '../Initializer.js';
|
||||
|
||||
import { getValueFromEnvironmentVariable } from '../utils/env-vars.js';
|
||||
import { HealthCheckableRequestClient } from '../utils/HealthCheckableRequestClient.js';
|
||||
|
||||
import type { BridgemanAccessibleAppClaims } from './types/BridgemanAccessibleAppClaims.js';
|
||||
|
||||
|
|
@ -101,6 +103,7 @@ type OAuthAppOptions<T extends BridgemanAccessibleAppClaims> = T & BasicOAuthApp
|
|||
export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extends App {
|
||||
private onAuth: OnAuthCallback;
|
||||
private saveSecret: (secret: string) => void | Promise<void>;
|
||||
private getAccessToken: () => Promise<string>;
|
||||
|
||||
private options: OAuthAppOptions<TCustomClaims>;
|
||||
|
||||
|
|
@ -153,11 +156,13 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
constructor(
|
||||
onAuth: OnAuthCallback,
|
||||
saveSecret: (secret: string) => void | Promise<void>,
|
||||
getAccessToken: () => Promise<string>,
|
||||
options?: OAuthAppOptions<TCustomClaims>
|
||||
) {
|
||||
super();
|
||||
this.onAuth = onAuth;
|
||||
this.saveSecret = saveSecret;
|
||||
this.getAccessToken = getAccessToken;
|
||||
this.options = options ?? {} as OAuthAppOptions<TCustomClaims>;
|
||||
}
|
||||
|
||||
|
|
@ -192,13 +197,14 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
// Because we need this for registration to work properly. It make sense to put it here
|
||||
app.getInitializer()
|
||||
.getRouter()
|
||||
.addOutsideFrameworkRoute('/.well-known/jwks.json');
|
||||
.addOutsideFrameworkRoute(BaseKeystore.WELL_KNOWN_URI);
|
||||
|
||||
this.client = await Client.setup<TCustomClaims>(
|
||||
app.getExpressApp(),
|
||||
baseAppUrl,
|
||||
this.onAuth,
|
||||
this.saveSecret,
|
||||
this.getAccessToken,
|
||||
{
|
||||
client_abbreviation: appAbbrv,
|
||||
subscription_required: this.options.subscription_required ?? false,
|
||||
|
|
@ -237,8 +243,9 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
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`,
|
||||
await (new HealthCheckableRequestClient('Authorization Server')).makeRequest(
|
||||
new URL(`https://account.bridgemanaccessible.ca/api/v1/apps/${encodeURIComponent(baseAppUrl.toString())}/status`),
|
||||
'GET',
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue