Skip to content

Commit

Permalink
Merge pull request #2719 from patrick-rodgers/version-3
Browse files Browse the repository at this point in the history
updating docs to fix errors #2709
  • Loading branch information
patrick-rodgers authored Jun 16, 2023
2 parents ea938a7 + da96175 commit d33b121
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions docs/concepts/auth-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ We support MSAL for both browser and nodejs and Azure Identity for nodejs by pro

Depending on which package you want to use you will need to install an additional package from the library because of the large dependencies.

For the NodeJS MSAL package:

`npm install @pnp/msaljsclient --save`

We support MSAL through the [msal-node](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/README.md) library.
We support MSAL through the [msal-node](https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-node/README.md) library which is included by the @pnp/nodejs package.

For the Azure Identity package:

Expand All @@ -18,15 +14,14 @@ We support Azure Identity through the [@azure/identity](https://github.com/Azure

## MSAL + NodeJS

The SPDefault and GraphDefault exported by the nodejs library include MSAL and takes the parameters directly. Please consider that ability deprecated and instead use the method shown below to chain the MSAL auth behavior and configure it independently.
The SPDefault and GraphDefault exported by the nodejs library include MSAL and takes the parameters directly.

The following samples reference a MSAL configuration that utilizes an Azure AD App Registration, these are samples that show the typings for those objects:

```TypeScript
import { SPDefault, GraphDefault } from "@pnp/nodejs";
import { spfi } from "@pnp/sp";
import { graphfi } from "@pnp/graph";
import { MSAL } from "@pnp/msaljsclient";
import { Configuration, AuthenticationParameters } from "msal";
import "@pnp/graph/users";
import "@pnp/sp/webs";
Expand All @@ -38,24 +33,43 @@ const configuration: Configuration = {
}
};

const authParams: AuthenticationParameters = {
scopes: ["https://graph.microsoft.com/.default"]
};
const sp = spfi("{site url}").using(SPDefault({
msal: {
config: configuration,
scopes: ["https://{tenant}.sharepoint.com/.default"],
},
}));

const sp = spfi("https://{tenant}.sharepoint.com/sites/dev").using(
SPDefault(),
MSAL(configuration, authParams)
);

const graph = graphfi().using(
GraphDefault(),
MSAL(configuration, authParams)
);
const graph = graphfi().using(GraphDefault({
msal: {
config: configuration,
scopes: ["https://graph.microsoft.com/.default"],
},
}));

const webData = await sp.web();
const meData = await graph.me();
```

## Use Nodejs MSAL behavior directly

It is also possible to use the MSAL behavior directly if you are composing your own strategies.

```TypeScript
import { SPDefault, GraphDefault, MSAL } from "@pnp/nodejs";

const sp = spfi("{site url}").using(SPDefault(), MSAL({
config: configuration,
scopes: ["https://{tenant}.sharepoint.com/.default"],
}));

const graph = graphfi().using(GraphDefault(), MSAL({
config: configuration,
scopes: ["https://graph.microsoft.com/.default"],
}));

```

## Azure Identity + NodeJS

The following sample shows how to pass the credential object to the AzureIdentity behavior including scopes.
Expand Down

0 comments on commit d33b121

Please sign in to comment.