Last active
March 29, 2021 03:52
-
-
Save anvilation/0609279492516aae69029eded6821072 to your computer and use it in GitHub Desktop.
SharePoint on MS Graph: Authentication Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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