Skip to content

Function: getMsGraphClientUserAuth()

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

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

Create a Microsoft Graph client using interactive user authentication via MSAL and Puppeteer. Open a browser login page, wait for the user to sign in, and exchange the auth code for a 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.resourceUrlstringA SharePoint resource URL to navigate to before authentication.

Returns

Promise<Client>

An authenticated Microsoft Graph client.

Example

ts
const client = await getMsGraphClientUserAuth(ctx, {
  clientId: 'app-client-id',
  tenantId: 'tenant-id',
  localPort: 3000,
  scopes: ['Mail.Send', 'Mail.ReadWrite'],
  resourceUrl: 'https://outlook.office.com/mail/',
});
const user = await client.api('/me').get();
console.log('Signed in as:', user.displayName);

Matterway Assistant SDK Documentation