Failed to fetch RP JWKS from specified endpoint: fetch is not defined
Closed this issue · 2 comments
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
-
Go to '...'
-
Click on '....'
-
Scroll down to '....'
-
See error
-
my data req.body is
req.body = {
grant_type: 'authorization_code',
code: 'S1234567A',
client_id: 'S1234567A',
redirect_uri: 'http://localhost:4444/assert',
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
client_assertion: 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkJ1WGZEaXYxQWZ2T3dSREM5RDNXODBXMFFtVGRQbmlrWnVyblFiNm1MdlUifQ.eyJpYXQiOjE2Nzk1OTc4NTIsImV4cCI6MTY3OTU5Nzk3MiwiYXVkIjoiaHR0cDovL2xvY2FsaG9zdDo1MTU2L3NpbmdwYXNzL3YyIiwiaXNzIjoiUzEyMzQ1NjdBIiwic3ViIjoiUzEyMzQ1NjdBIn0.JScopi8LQUdBEViP-P99aqHVfdLIu0eyEL0ZyyMOBdSpbDuRxJnKwGiJHtFfNCKDG94nm7WrnI-Qy4JfZ5_qLg'
}
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Os - MacOs
Browser - opera/chrome
version - latest
Additional context
Add any other context about the problem here.
Requesting { method: 'post', url: 'http://localhost:5156/singpass/v2/token' }
Error occurred while responding to request {
method: 'post',
url: 'http://localhost:5156/singpass/v2/token',
status: 400,
data: 'Failed to fetch RP JWKS from specified endpoint: fetch is not defined'
}
Index.js
import express from 'express'
import cookieParser from 'cookie-parser'
import { Singpass } from "@govtechsg/singpass-myinfo-oidc-helper"
const key1 = {
crv: 'P-256',
alg: ['ES256'],
ext: false,
x: 'Sp3KpzPjwcCF04_W2GvSSf-vGDvp3Iv2kQYqAjnMB-Y',
y: 'lZmecT2quXe0i9f7b4qHvDAFDpxs0oxCoJx4tOOqsks',
d: 'hRVo5TGE_d_4tQC1KEQIlCdo9rteZmLSmaMPpFOjeDI',
kty: 'EC',
}
const key = {
"key": JSON.parse(JSON.stringify(key1)),
"format": 'json',
"alg": 'ES256',
}
const server = new Singpass.NdiOidcHelper({
oidcConfigUrl: 'http://localhost:5156/singpass/v2/.well-known/openid-configuration',
clientID: 'S1234567A',
redirectUri: 'http://localhost:4444/assert',
jweDecryptKey: JSON.parse(JSON.stringify(key)),
clientAssertionSignKey: JSON.parse(JSON.stringify(key)),
})
const app = express()
app.use(cookieParser())
app.get('/login', async (req, res) => {
const redirectURL = await server.constructAuthorizationUrl('kiosk001', 'S8979373D', 'http://localhost:5156/singpass/v2/authorize')
res.cookie('connect.sid', '').redirect(redirectURL)
})
app.get('/test', async (req, res) => {
const token = await server.getTokens("S1234567A")
console.log("singpass", token)
})
app.get('/logout', (req, res, next) => {
const out = client.logoutOfSession()
res.send(200).send(out)
})
const port = process.env.PORT || 4444
app.listen(4444, () => console.log(`Listening on port ${port}`))
I'm trying to get token but unable
Please help me here
This has nothing to do with this repository.
You are attempting to use the global fetch
api on an environment where it is not defined.
For node the fetch
api has been implemented since node 18. If you need to target an earlier version of node then you need something like node-fetch
.