Appearance
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
| Parameter | Type | Description |
|---|---|---|
ctx | Context | The SDK context with a browser instance. |
props | { clientId: string; tenantId: string; localPort: number; scopes: string[]; resourceUrl: string; } | The authentication properties. |
props.clientId | string | The Azure AD application client ID. |
props.tenantId | string | The Azure AD tenant ID. |
props.localPort | number | The local port for the redirect URI. |
props.scopes | string[] | The authentication scopes. |
props.resourceUrl | string | A 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);