diff --git a/package.json b/package.json index 5c62745..1762361 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "create-ba-web-app": "node ./bin/create-project.js" }, "dependencies": { - "@BridgemanAccessible/ba-auth": "^1.0.21", + "@BridgemanAccessible/ba-auth": "^1.0.22", "@BridgemanAccessible/ba-logging": "^1.0.1", "express": "^4.19.2", "fs-extra": "^11.2.0", diff --git a/src/oauth/OAuthApp.ts b/src/oauth/OAuthApp.ts index a17746b..384aefc 100644 --- a/src/oauth/OAuthApp.ts +++ b/src/oauth/OAuthApp.ts @@ -68,6 +68,8 @@ export class OAuthApp extends App { private auth_default_response_mode?: 'query' | 'fragment' | 'form_post'; private client_secret?: string; + private client: Client; + /** * Create a new OAuth app * @@ -132,6 +134,11 @@ export class OAuthApp extends App { } } + /** Returns the OAuthApp's Client instance (which is useful for managing keys, creating resource request, etc...) */ + getClient(): Client { + return this.client; + } + /** * Setup the OAuth client * @@ -160,7 +167,7 @@ export class OAuthApp extends App { .getRouter() .addOutsideFrameworkRoute('/.well-known/jwks.json'); - const client = await Client.setup( + this.client = await Client.setup( app.getExpressApp(), baseAppUrl, this.onAuth, @@ -185,7 +192,7 @@ export class OAuthApp extends App { } ); - client.getSetupRoutes().forEach((route) => { + this.client.getSetupRoutes().forEach((route) => { logMessage(`Adding outside framework route: ${route}`, LogLevel.DEBUG); app.getInitializer().getRouter().addOutsideFrameworkRoute(route); }); @@ -200,7 +207,7 @@ export class OAuthApp extends App { * * @param app The Express app object (that is now listening) */ - async onStart(app: App, callback?: (app: App) => void | Promise) { + private async onStart(app: App, callback?: (app: OAuthApp) => void | Promise) { try { // Setup the OAuth client. // This is done here because we need the client to be serving/listening for requests for the auth library stuff to work @@ -208,7 +215,7 @@ export class OAuthApp extends App { await this.setupOAuthClient(app); if(typeof callback !== 'undefined') { - await callback.bind(this)(app); + await callback(this); } } catch(err) { @@ -228,7 +235,7 @@ export class OAuthApp extends App { * And doesn't have to worry about the OAuth details to make this work. * Though it does provide tweaking the OAuth details via options provided to the constructor. */ - async run(initializer?: T, callback?: (app: App) => void | Promise) { + async run(initializer?: T, callback?: (app: OAuthApp) => void | Promise) { await super.run(initializer, async (app: App) => this.onStart(app, callback)); } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 946a171..f801de4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@BridgemanAccessible/ba-auth@^1.0.21": - version "1.0.21" - resolved "https://npm.pkg.bridgemanaccessible.ca/@BridgemanAccessible/ba-auth/-/ba-auth-1.0.21.tgz#288b72f5f40b634ca34ace34400857e0fe62cb20" - integrity sha512-3KkRj1SwYUot64/CoLGOojPLORTTXhqBBJIMVS4bpXOj695TXOluoNAv2dH0n61cfKCbBxbVnwt6h1AQq7cvfw== +"@BridgemanAccessible/ba-auth@^1.0.22": + version "1.0.22" + resolved "https://npm.pkg.bridgemanaccessible.ca/@BridgemanAccessible/ba-auth/-/ba-auth-1.0.22.tgz#3232029d562023f4d4a745accd9c0bce4e99a1fe" + integrity sha512-GI9Bx+zSPpj7mB6X5dzYw24/KkFA9vCniUGe5soiayhkZXSNucEKMuLjPA9VZAKfDsf1I3ygMLAyjrW+Rm0wlQ== dependencies: "@BridgemanAccessible/ba-logging" "^1.0.1" "@azure/identity" "^4.0.1"