Skip to content

Commit 8522a15

Browse files
authored
Code cleanup in preparation for logout validation (#658)
* Code cleanup in preparation for logout validation * Update package-lock
1 parent f7a8bb5 commit 8522a15

File tree

6 files changed

+102
-132
lines changed

6 files changed

+102
-132
lines changed

README.md

+62-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Passport-SAML
22

3-
[![Build Status](https://github.com/node-saml/passport-saml/workflows/Build%20Status/badge.svg)](https://github.com/node-saml/passport-saml/actions?query=workflow%3ABuild%Status) [![GitHub version](https://badge.fury.io/gh/node-saml%2Fpassport-saml.svg)](https://badge.fury.io/gh/node-saml%2Fpassport-saml) [![npm version](https://badge.fury.io/js/passport-saml.svg)](http://badge.fury.io/js/passport-saml) [![NPM](https://nodei.co/npm/passport-saml.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/passport-saml/) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
3+
[![Build Status](https://github.com/node-saml/passport-saml/workflows/Build%20Status/badge.svg)](https://github.com/node-saml/passport-saml/actions?query=workflow%3ABuild%Status) [![GitHub version](https://badge.fury.io/gh/node-saml%2Fpassport-saml.svg)](https://badge.fury.io/gh/node-saml%2Fpassport-saml) [![npm version](https://badge.fury.io/js/passport-saml.svg)](http://badge.fury.io/js/passport-saml) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
4+
5+
[![NPM](https://nodei.co/npm/passport-saml.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/passport-saml/)
46

57
This is a [SAML 2.0](http://en.wikipedia.org/wiki/SAML_2.0) authentication provider for [Passport](http://passportjs.org/), the Node.js authentication library.
68

@@ -10,9 +12,9 @@ Passport-SAML has been tested to work with Onelogin, Okta, Shibboleth, [SimpleSA
1012

1113
## Installation
1214

13-
$ npm install passport-saml
14-
15-
/
15+
```shell
16+
npm install passport-saml
17+
```
1618

1719
## Usage
1820

@@ -88,27 +90,28 @@ Using multiple providers supports `validateInResponseTo`, but all the `InRespons
8890
The profile object referenced above contains the following:
8991

9092
```typescript
91-
type Profile = {
92-
issuer?: string;
93+
export interface Profile {
94+
issuer: string;
9395
sessionIndex?: string;
94-
nameID?: string;
95-
nameIDFormat?: string;
96+
nameID: string;
97+
nameIDFormat: string;
9698
nameQualifier?: string;
9799
spNameQualifier?: string;
100+
ID?: string;
98101
mail?: string; // InCommon Attribute urn:oid:0.9.2342.19200300.100.1.3
99102
email?: string; // `mail` if not present in the assertion
100-
getAssertionXml(): string; // get the raw assertion XML
101-
getAssertion(): object; // get the assertion XML parsed as a JavaScript object
102-
getSamlResponseXml(): string; // get the raw SAML response XML
103-
ID?: string;
104-
} & {
103+
["urn:oid:0.9.2342.19200300.100.1.3"]?: string;
104+
getAssertionXml?(): string; // get the raw assertion XML
105+
getAssertion?(): Record<string, unknown>; // get the assertion XML parsed as a JavaScript object
106+
getSamlResponseXml?(): string; // get the raw SAML response XML
105107
[attributeName: string]: unknown; // arbitrary `AttributeValue`s
106-
};
108+
}
107109
```
108110

109111
#### Config parameter details:
110112

111-
- **Core**
113+
**Core**
114+
112115
- `callbackUrl`: full callbackUrl (overrides path/protocol if supplied)
113116
- `path`: path to callback; will be combined with protocol and server host information to construct callback url if `callbackUrl` is not specified (default: `/saml/consume`)
114117
- `protocol`: protocol for callback; will be combined with path and server host information to construct callback url if `callbackUrl` is not specified (default: `http://`)
@@ -122,7 +125,9 @@ type Profile = {
122125
- `signatureAlgorithm`: optionally set the signature algorithm for signing requests, valid values are 'sha1' (default), 'sha256', or 'sha512'
123126
- `digestAlgorithm`: optionally set the digest algorithm used to provide a digest for the signed data object, valid values are 'sha1' (default), 'sha256', or 'sha512'
124127
- `xmlSignatureTransforms`: optionally set an array of signature transforms to be used in HTTP-POST signatures. By default this is `[ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#' ]`
125-
- **Additional SAML behaviors**
128+
129+
**Additional SAML behaviors**
130+
126131
- `additionalParams`: dictionary of additional query params to add to all requests; if an object with this key is passed to `authenticate`, the dictionary of additional query params will be appended to those present on the returned URL, overriding any specified by initialization options' additional parameters (`additionalParams`, `additionalAuthorizeParams`, and `additionalLogoutParams`)
127132
- `additionalAuthorizeParams`: dictionary of additional query params to add to 'authorize' requests
128133
- `identifierFormat`: optional name identifier format to request from identity provider (default: `urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress`)
@@ -147,31 +152,38 @@ type Profile = {
147152
{
148153
entries: [ // required
149154
{
150-
providerId: 'yourProviderId', // required for each entry
151-
name: 'yourName', // optional
152-
loc: 'yourLoc', // optional
153-
}
155+
providerId: "yourProviderId", // required for each entry
156+
name: "yourName", // optional
157+
loc: "yourLoc", // optional
158+
},
154159
],
155-
getComplete: 'URI to your complete IDP list', // optional
160+
getComplete: "URI to your complete IDP list", // optional
156161
},
157162
],
158163
proxyCount: 2, // optional
159-
requesterId: 'requesterId', // optional
160-
}
164+
requesterId: "requesterId", // optional
165+
};
161166
```
162167

163-
- **InResponseTo Validation**
168+
**InResponseTo Validation**
169+
164170
- `validateInResponseTo`: if truthy, then InResponseTo will be validated from incoming SAML responses
165171
- `requestIdExpirationPeriodMs`: Defines the expiration time when a Request ID generated for a SAML request will not be valid if seen in a SAML response in the `InResponseTo` field. Default is 8 hours.
166172
- `cacheProvider`: Defines the implementation for a cache provider used to store request Ids generated in SAML requests as part of `InResponseTo` validation. Default is a built-in in-memory cache provider. For details see the 'Cache Provider' section.
167-
- **Issuer Validation**
173+
174+
**Issuer Validation**
175+
168176
- `idpIssuer`: if provided, then the IdP issuer will be validated for incoming Logout Requests/Responses. For ADFS this looks like `https://acme_tools.windows.net/deadbeef`
169-
- **Passport**
177+
178+
**Passport**
179+
170180
- `passReqToCallback`: if truthy, `req` will be passed as the first argument to the verify callback (default: `false`)
171181
- `name`: Optionally, provide a custom name. (default: `saml`). Useful If you want to instantiate the strategy multiple times with different configurations,
172182
allowing users to authenticate against multiple different SAML targets from the same site. You'll need to use a unique set of URLs
173183
for each target, and use this custom name when calling `passport.authenticate()` as well.
174-
- **Logout**
184+
185+
**Logout**
186+
175187
- `logoutUrl`: base address to call with logout requests (default: `entryPoint`)
176188
- `additionalLogoutParams`: dictionary of additional query params to add to 'logout' requests
177189
- `logoutCallbackUrl`: The value with which to populate the `Location` attribute in the `SingleLogoutService` elements in the generated service provider metadata.
@@ -188,7 +200,10 @@ const bodyParser = require("body-parser");
188200
app.post(
189201
"/login/callback",
190202
bodyParser.urlencoded({ extended: false }),
191-
passport.authenticate("saml", { failureRedirect: "/", failureFlash: true }),
203+
passport.authenticate("saml", {
204+
failureRedirect: "/",
205+
failureFlash: true,
206+
}),
192207
function (req, res) {
193208
res.redirect("/");
194209
}
@@ -241,11 +256,11 @@ Authentication requests sent by Passport-SAML can be signed using RSA signature
241256

242257
To select hashing algorithm, use:
243258

244-
```js
259+
```javascript
245260
...
246-
signatureAlgorithm: 'sha1' // (default, but not recommended anymore these days)
247-
signatureAlgorithm: 'sha256', // (preferred - your IDP should support it, otherwise think about upgrading it)
248-
signatureAlgorithm: 'sha512' // (most secure - check if your IDP supports it)
261+
signatureAlgorithm: "sha1" // (default, but not recommended anymore these days)
262+
signatureAlgorithm: "sha256" // (preferred - your IDP should support it, otherwise think about upgrading it)
263+
signatureAlgorithm: "sha512" // (most secure - check if your IDP supports it)
249264
...
250265
```
251266

@@ -255,14 +270,14 @@ Formats supported for `privateKey` field are,
255270

256271
1. Well formatted PEM:
257272

258-
```
273+
```text
259274
-----BEGIN PRIVATE KEY-----
260275
<private key contents here delimited at 64 characters per row>
261276
-----END PRIVATE KEY-----
262277
263278
```
264279

265-
```
280+
```text
266281
-----BEGIN RSA PRIVATE KEY-----
267282
<private key contents here delimited at 64 characters per row>
268283
-----END RSA PRIVATE KEY-----
@@ -290,8 +305,8 @@ cert: "MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==";
290305

291306
If you have a certificate in the binary DER encoding, you can convert it to the necessary PEM encoding like this:
292307

293-
```bash
294-
openssl x509 -inform der -in my_certificate.cer -out my_certificate.pem
308+
```shell
309+
openssl x509 -inform der -in my_certificate.cer -out my_certificate.pem
295310
```
296311

297312
If the Identity Provider has multiple signing certificates that are valid (such as during the rolling from an old key to a new key and responses signed with either key are valid) then the `cert` configuration key can be an array:
@@ -359,17 +374,17 @@ To support this scenario you can provide an implementation for a cache provider
359374

360375
```javascript
361376
{
362-
saveAsync: async function(key, value) {
363-
// saves the key with the optional value, returns the saved value
364-
},
365-
getAsync: async function(key) {
366-
// returns the value if found, null otherwise
367-
},
368-
removeAsync: async function(key) {
369-
// removes the key from the cache, returns the
370-
// key removed, null if no key is removed
371-
}
372-
}
377+
saveAsync: async function (key, value) {
378+
// saves the key with the optional value, returns the saved value
379+
},
380+
getAsync: async function (key) {
381+
// returns the value if found, null otherwise
382+
},
383+
removeAsync: async function (key) {
384+
// removes the key from the cache, returns the
385+
// key removed, null if no key is removed
386+
},
387+
};
373388
```
374389

375390
Provide an instance of an object which has these functions passed to the `cacheProvider` config option when using Passport-SAML.

0 commit comments

Comments
 (0)