AadTokenProvider class

This class allows a developer to obtain OAuth2 tokens from Azure AD.

OAuth2 tokens are used to authenticate the user from the SharePoint page to other services such as PowerBI, Sway, Exchange, Yammer, etc.

Implements

Remarks

This class is marked as @sealed. Subclasses should not extend it.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the AadTokenProvider class.

Methods

getToken(resourceEndpoint, useCachedToken)

Fetches the AAD OAuth2 token for a resource if the user that's currently logged in has access to that resource.

The OAuth2 token should not be cached by the caller since it is already cached by the method itself.

Events

tokenAcquisitionEvent

Notifies the developer when Token Acquisition requires user action.

Method Details

getToken(resourceEndpoint, useCachedToken)

Fetches the AAD OAuth2 token for a resource if the user that's currently logged in has access to that resource.

The OAuth2 token should not be cached by the caller since it is already cached by the method itself.

getToken(resourceEndpoint: string, useCachedToken?: boolean): Promise<string>;

Parameters

resourceEndpoint
string

the resource for which the token should be obtained

useCachedToken
boolean

Allows the developer to specify if cached tokens should be returned. An example of a resourceEndpoint would be https://graph.microsoft.com

Returns

Promise<string>

A promise that will be fullfiled with the token or that will reject with an error message

Event Details

tokenAcquisitionEvent

Notifies the developer when Token Acquisition requires user action.

readonly tokenAcquisitionEvent: SPEvent<TokenAcquisitionEventArgs>;

Returns