Fix using gateway uri

This commit is contained in:
Erki Aas 2023-07-27 21:31:33 +03:00
parent 5e8507d3b0
commit beb86f7b23
2 changed files with 33 additions and 1048 deletions

37
app.js
View File

@ -7,12 +7,12 @@ async function run() {
app.use(bodyParser.urlencoded()); app.use(bodyParser.urlencoded());
app.use(bodyParser.json()) app.use(bodyParser.json())
const issuer = await Issuer.discover(process.env.OIDC_GATEWAY_URL); const issuer = await Issuer.discover(process.env.OIDC_GATEWAY_URI);
console.log('Discovered issuer %s %O', issuer.issuer, issuer.metadata); console.log('Discovered issuer %s %O', issuer.issuer, issuer.metadata);
const client = new issuer.Client({ const client = new issuer.Client({
client_id: process.env.OIDC_CLIENT_ID, client_id: process.env.OIDC_CLIENT_ID,
client_secret: process.env.OIDC_CLIENT_SECRET, client_secret: process.env.OIDC_CLIENT_SECRET,
redirect_uris: JSON.parse(process.env.OIDC_REDIRECT_URIS), redirect_uris: [process.env.OIDC_REDIRECT_URIS],
response_types: ['code'], response_types: ['code'],
// id_token_signed_response_alg (default "RS256") // id_token_signed_response_alg (default "RS256")
}) })
@ -23,21 +23,48 @@ async function run() {
app.get('/', async function (req, res) { app.get('/', async function (req, res) {
let url = client.authorizationUrl({ let url = client.authorizationUrl({
redirect_uri: process.env.CLIENT_URL + '/cb', redirect_uri: process.env.CLIENT_URL + '/cb',
scope: 'openid profile', scope: 'openid profile offline_access',
response_type: 'code', response_type: 'code',
code_challenge, code_challenge,
code_challenge_method: 'S256', code_challenge_method: 'S256',
}); });
res.redirect(url); res.redirect(url);
}); });
app.get('/cb', async function (req, res) { app.get('/cb', async function (req, res) {
const params = client.callbackParams(req); const params = client.callbackParams(req);
const tokenSet = await client.callback(process.env.CLIENT_URL + '/cb', params,{ code_verifier }); const tokenSet = await client.callback(process.env.CLIENT_URL + '/cb', params,{ code_verifier });
const userinfo = await client.userinfo(tokenSet.access_token); const userinfo = await client.userinfo(tokenSet.access_token);
console.log('userinfo %j', userinfo); res.send(
res.send(userinfo) `
<code>${JSON.stringify(userinfo)}</code>
<code>${JSON.stringify(tokenSet)}</code>
<a href="/refresh/${tokenSet.refresh_token}">refresh</a>
<a href="/access/${tokenSet.access_token}">access</a>
`
)
}); });
app.get('/access/:token', async function (req, res) {
const access = await client.userinfo(req.params.token)
res.send(
`
<code>${JSON.stringify(access)}</code>
<a href="/access/${req.params.token}">access</a>
`
)
});
app.get('/refresh/:token', async function (req, res) {
const refresh = await client.refresh(req.params.token)
res.send(
`
<code>${JSON.stringify(refresh)}</code>
<a href="/refresh/${refresh.refresh_token}">refresh</a>
`
)
});
app.listen(3000); app.listen(3000);
} }

1044
package-lock.json generated

File diff suppressed because it is too large Load Diff