I use the this library to use oidc
with nodejs
What I need is the following:
user login with user password, or have the data already the session cookie. this is calling to my app root route
"/"
I've registered the application already in the
authorization server
, the auth server should call to my theapp/redirect
from the auth server I took the clientId and client secret and put it in the app.
When the user logged-in the auth server should call to my application redirect route .
From the
oidc
strategy I need to get thetokenset.claims();
and from ittokenset.id_token
, the user token. , in the redirect call
It should be with
response_type: 'code',
https://github.com/auth0/express-openid-connect#getting-started
The problem is the getUser
function is called (while debug the application) however I got the userIdentity
from req.session.userIdentity
which is undefined
, any idea what could be wrong here?
We are having the same old implementation which using OIDC and it works for the same auth server and clientid and secret.
const { auth, requiresAuth } = require('express-openid-connect');
const session = require('express-session');
const bodyParser = require('body-parser');
module.exports = async (app) => {
const ClientId = process.env.CI;
const ClientSecret = process.env.CS;
const URL = process.env.S_URL;
app.use(session({
name: 'bat-auth',
secret: 'cookie-secret',
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(auth({
clientSecret: ClientSecret,
issuerBaseURL: `${URL}`,
clientID: ClientId,
baseURL: process.env.REDT_URL,
redirectUriPath: '/redirect', //my app redirect route
authorizationParams: {
response_type: 'code',
response_mode: 'form_post',
scope: 'openid',
},
async handleCallback(req, res, next) {
req.session.openidTokens = req.openidTokens;
console.log('---req.openidTokens', req.openidTokens);
req.session.userIdentity = req.openidTokens.claims();
next();
},
async getUser(req) {
return req.session.userIdentity;
},
}));
app.get('/', (req, res) => {
const tokenSet = req.openid.makeTokenSet(req.session.openidTokens);
console.log(`tokenset root: ${tokenSet}`);
res.send(req.isAuthenticated() ? 'Logged in' : 'Logged out');
});
app.get('/redirect', async (req, res) => {
const tokenSet = req.openid.makeTokenSet(req.session.openidTokens);
console.log(`tokenset: ${tokenSet}`);
console.log('redirect called');
res.send('redirect called');
});
I should use form post and at the end, what I need is to get from the tokenset
, user.id_token
?
This is what I've, and verified!
- ClientID from auth server
- ClientSecret from auth server
- Config the auth server my app
redirect
path, which should called me after successful login- I've also the
aud
key
Btw, while debug the application it doesn't stops add handleCallback function , but it stops on the getUser
app first, not sure what could be the reason...
'/redirect'
also and still got the same error, any other idea? does my other configuration looks ok? – Nikolos