Skip to content

Instantly share code, notes, and snippets.

@anvilation
Last active March 29, 2021 03:52
Show Gist options
  • Save anvilation/0609279492516aae69029eded6821072 to your computer and use it in GitHub Desktop.
Save anvilation/0609279492516aae69029eded6821072 to your computer and use it in GitHub Desktop.
SharePoint on MS Graph: Authentication Provider
export class DLAuthenticationProvider implements AuthenticationProvider {
config: MsalConfig = {
auth: {
clientId: '',
authority: '',
clientSecret: '',
graphendpoint: '',
}
};
tokenrequest: any;
cca: msal.ConfidentialClientApplication;
constructor(config: MsalConfig) {
this.config = config;
this.tokenrequest = {
scopes: [config.auth.graphendpoint + '.default'],
};
this.cca = new msal.ConfidentialClientApplication(this.config);
}
public async getAccessToken(): Promise<string> {
return new Promise((ok, fail) => {
this.cca.acquireTokenByClientCredential(this.tokenrequest)
.then((response) => {
ok(response.accessToken);
})
.catch((error) => {
fail(error);
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment