0

I got a node.js application and I'm trying to use the AdalFetchClient of PnPjs to fetch some data from sharepoint.

sp.setup({
  sp: {
    baseUrl: "https://placeholder.sharepoint.com",
    fetchClientFactory: () => {
      return new AdalFetchClient("tenantId", "azure_clientId", "azure_clientSecret");
    },
  },
});

await sp.web.getAppCatalog().get();

I get this error: Error making HttpClient request in queryable [401] Unauthorized ::> {"error_description":"Invalid issuer or signature."}

I setup the permissions of my azure active directory app like so: Azure App permissions

I granted all the permissions to the tenant I'm trying to fetch data from: Granted permissions to Azure App

The example I used is here: https://pnp.github.io/pnpjs/nodejs/adal-fetch-client/ I also tried to use the AdalFetchClient with graph.. which is working. Only the sharepoint api seems to have a problem.

Syntarex
  • 11
  • 2
  • Did you configure a self-signed X.509 certificate in your Azure AD app by following: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread? – Allen Wu Sep 25 '20 at 04:42
  • I actually didn't! Thanks for this resource. Do you know how to add the certificate to the AdalFetchClient of pnp-js? I really dont want to use powershell to be honest. :D – Syntarex Sep 25 '20 at 07:37
  • Or do you know how to send the certificate as http header? – Syntarex Sep 25 '20 at 07:48
  • I have no idea. I think you should follow the official document. – Allen Wu Sep 25 '20 at 08:00
  • Please keep posted to let me know if it resolves your issue. – Allen Wu Sep 25 '20 at 08:10

1 Answers1

0

I found the solution. There is a AdalCertificateFetchClient which requires the following paramters:

  • Tenant-ID
  • Azure App Client ID
  • Thumbprint of your x.509 certificate
  • The private key of your x.509 certificate
  • The root url of the sharepoint you want to connect to

So first of all you have to create a x.509 certificate. I used this tutorial for this. (Thanks for that)

After that you have to get your thumbprint by installing the certificate to your local machine and following this steps

Last step is to get your private key of your certificate. For that you have to install openssl for windows and follow this steps

Now you can use your AdalCertificateFetchClient

Syntarex
  • 11
  • 2