File tree Expand file tree Collapse file tree
runner/src/server/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments