Skip to content

Function: getSharePointTokenUserAuth()

ts
function getSharePointTokenUserAuth(ctx: Context, props: {
  clientId: string;
  tenantId: string;
  localPort: number;
  scopes: string[];
  resourceUrl?: string;
}): Promise<string>;

Defined in: src/ms-graph/sharepointGraphEval.ts:37

Get a SharePoint access token using interactive user authentication via MSAL and Puppeteer. Open a browser login page, wait for the user to sign in, and return the token.

Parameters

ParameterTypeDescription
ctxContextThe SDK context with a browser instance.
props{ clientId: string; tenantId: string; localPort: number; scopes: string[]; resourceUrl?: string; }The authentication properties.
props.clientIdstringThe Azure AD application client ID.
props.tenantIdstringThe Azure AD tenant ID.
props.localPortnumberThe local port for the redirect URI.
props.scopesstring[]The authentication scopes.
props.resourceUrl?stringOptional resource URL to navigate to before authentication.

Returns

Promise<string>

The SharePoint access token string.

Example

ts
const token = await getSharePointTokenUserAuth(ctx, {
  clientId: 'app-client-id',
  tenantId: 'tenant-id',
  localPort: 3000,
  scopes: ['https://graph.microsoft.com/.default'],
  resourceUrl: 'https://contoso.sharepoint.com/sites/ProjectAlpha',
});
console.log('Got token of length:', token.length);

Matterway Assistant SDK Documentation