Skip to content

Commit 43a06ec

Browse files
committed
adding back msal
1 parent e5b1e3a commit 43a06ec

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ConfidentialClientApplication } from "@azure/msal-node";
2+
import { MsalAuthorizerConfig } from "@xgovformbuilder/model";
3+
4+
export class MsalAuthorizer {
5+
private readonly msal: ConfidentialClientApplication;
6+
private readonly scopes: string[];
7+
8+
constructor(config: MsalAuthorizerConfig) {
9+
this.scopes = config.scopes;
10+
this.msal = new ConfidentialClientApplication({
11+
auth: {
12+
clientId: config.clientId,
13+
clientSecret: config.clientSecret,
14+
authority: `https://login.microsoftonline.com/${config.tenantId}`,
15+
},
16+
});
17+
}
18+
19+
async getToken(): Promise<string> {
20+
const token = await this.msal.acquireTokenByClientCredential({
21+
scopes: this.scopes,
22+
});
23+
if (!token?.accessToken) throw new Error("Failed to acquire access token");
24+
return token.accessToken;
25+
}
26+
}

0 commit comments

Comments
 (0)