Initialising spfxContext for a different user in pnp/sp

838 views Asked by At

I'm trying to build an spFx app, that uses a different user to access lists and libraries than the logged in user. The logged in user won't have the permissions to access the lists directly but only via the app. But I can't find a way to initialize sp for a different user than the currently logged in user.

The standard method just gives me the logged in user:

sp.setup({
    spfxContext: this.context
});

The setup method for nodejs looks promising but won't work within an spFx app:

sp.setup({
    sp: {
        fetchClientFactory: () => {
            return new SPFetchClient("{your site url}", "{your client id}", "{your client secret}");
        },
    },
});

I also calling sharepoint via MSAL:

sp.setup({
    sp: {
        fetchClientFactory: MsalClientSetup({
            auth: {
                authority: "https://login.microsoftonline.com/mytentant.onmicrosoft.com",
                clientId: "00000000-0000-0000-0000-000000000000",
                redirectUri: "https://mytentant.sharepoint.com/sites/dev/SitePages/test.aspx",
            },
        }, ["https://mytentant.sharepoint.com/.default"]),
    },
});

But as soon as I access sp I get this error:

Unhandled Rejection (Error): You must supply absolute urls to MsalClient.fetch.

Also I don't see any option to provide the client secret in this MSAL logic.

I hope anybody can point me in the right direction. Thanks in advance!

0

There are 0 answers