-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathjar.js
More file actions
53 lines (46 loc) · 1.75 KB
/
Copy pathjar.js
File metadata and controls
53 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const express = require('express');
const { auth } = require('../');
const { privateJWK, privatePEM } = require('../end-to-end/fixture/jwk');
const app = express();
// JAR (JWT-Secured Authorization Requests) demo.
//
// When `requestObjectSigningKey` is set, the SDK signs all authorization
// parameters into a JWT and sends it as the `request` parameter, so the
// /authorize redirect carries only `client_id` and `request`. Combined with PAR
// (recommended for FAPI), the signed request object is POSTed to /oauth/par and
// only an opaque `request_uri` appears in the browser redirect.
//
// `requestObjectSigningAlg` is always required - Web Crypto algorithm names are
// not valid JWA `alg` values.
//
// Run with: node examples/run_example.js jar.js
// The mock OIDC provider is auto-started. Login with any username/password.
app.use(
auth({
authRequired: false,
authorizationParams: {
response_type: 'code',
},
// The mock provider's 'hri-client' is registered for private_key_jwt + JAR.
// clientAssertionSigningKey authenticates the token exchange; the same key
// pair signs the JAR request object here. In production they can differ.
clientAuthMethod: 'private_key_jwt',
clientAssertionSigningKey: privateJWK,
pushedAuthorizationRequests: true,
requestObjectSigningKey: privatePEM,
requestObjectSigningAlg: 'RS256',
// Optional: set a `kid` in the signed request object's JWT header.
// requestObjectSigningKeyId: 'my-key-id',
}),
);
app.get('/', (req, res) => {
if (req.oidc.isAuthenticated()) {
res.send(
`<p>Logged in as <strong>${req.oidc.user.sub}</strong></p>` +
`<a href="/logout">logout</a>`,
);
} else {
res.send('<a href="/login">login</a>');
}
});
module.exports = app;