Pnpjs: "Unsupported security Token" Error using Fetchclient with Client_id and secret

Created on 28 Dec 2020  路  3Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [X ] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [ latest ]

Expected / Desired Behavior / Question

Authentication should be successfull.

Observed Behavior

Error: Error making HttpClient request in queryable [401] Unauthorized ::> {"error_description":"Unsupported security token."} is thrown

Steps to Reproduce

I use the simple setup for accessing a sharepoint as described in the documentation:

```
import { SPFetchClient } from "@pnp/nodejs-commonjs";
import { sp } from "@pnp/sp-commonjs";

sp.setup({
sp: {
fetchClientFactory: () => {
return new SPFetchClient(BASE_URL, CLIENT_ID, CLIENT_SECRET);
},
},
});

sp.web.get()
.then( w=> {
console.log("Url : " + w.Url);
console.log("Title : " + w.Title +"\nDesc: " + w.Description);
console.log(JSON.stringify(w));
})
.catch((e) => {
console.log(e);
});
```

code details needed not a bug question

Most helpful comment

Hi, actually really was my mistake. I thought it was almost impossible to do something wrong in this few lines of code, but i acutally had a typo in my client-id and got confused by the error that was raised.

All 3 comments

Hi @rohansaw,

Definitely not a bug in the library. Legacy Add-In Only auth didn't change in years.
Is it SharePoint Online or On-Prem? Add-In Only auth won't work in On-Prem.
If it's SPO, I assume then a German cloud, then please check you are providing SPOAuthEnv.Germany

Hi, actually really was my mistake. I thought it was almost impossible to do something wrong in this few lines of code, but i acutally had a typo in my client-id and got confused by the error that was raised.

No problem, thanks for coming back with the update! Happy holidays!

Was this page helpful?
0 / 5 - 0 ratings