Next Auth Session callback not triggered - next

I am new to next-auth.
I am trying to add redirection of user to the sign page if the session expires through session callback. But it seems that session callback is not triggered when the session expires.
I am using the Credentials Provider.
I tried to print simple message when the session callback gets called. I saw the console message printing when session exists. I expected that the session callback still get triggered when the session expires.

Related

How does the user session work for OAuth2 authentication type Jhipster application?

An Oauth2 client application generated by Jhipster has a behaviour issue after some idle time. After a signed-in user has some idle time on the application, interaction with the application will lead to an undesired behavior such as a data isn't fetched from the database.
I have learned that user session data is stored in a form of a cookie on the front end. For the Vue front-end, searching
this.$cookie.set(
yields no result.
I do see JSESSIONID in a request header after a user signs into the application. So, I assume that the session id also is stored somewhere on the server. For every REST request, the server would verify the session id in the request header by comparing it with the session id on the server. When the session is time out, the server no longer has the session id. Any REST request from the point will lead to undesired behaviour in the current implementation. A filter is needed to verify a REST request session id with the server.
I have a look at the code in the security package as well as the security configuration. But, I don't see any code dealing with a user session.
How does the server work in this regard?
Update:
To deal with an invalid user session for a sign-in, I notice that the ExceptionHandlerExceptionResolver will handle the InsufficientAuthenticationException after refreshing a browser. Otherwise, the exception won't be handled. How to resolve this issue?

Generate unique sessionId with Express Cookie-Session

I'm using node/express.js with cookie-session in my application.
Currently, when a user logs in a cookie is stored in their browser with a value, for example: session: ABC123. If the user logs out, the cookie is deleted. When the user logs back in, the same cookie and value are stored in the browser session: ABC123.
I am getting the same session user_sid whenever i login.
i want to randomize the session user_sid every time the user logs in.
There is no notion of a session id with the cookie-session package.
In the typical scenario where the session data is stored on the server, a session id is generated that maps to a given user session data. This is this session id that is kept in the session cookie.
With the cookie-session package however, the session data itself is stored in the cookie - as opposed to on the server -, so there is no need for such a mapping or a session id at all. So in effect and unless the session data is actually updated from one session to another, the session cookie will be the same.
You want to call session.regenerate() when the user successfully login, that will do what you want and also address session fixation attack

domain name is getting replaced with github.com in github ouath call

http://**XYZ.com**/login/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2F**XYZIP**%3A3000%2Fauth%2Fgithub%2Fcallback&scope=user%3Aemail&client_id=34940ae24cfd171d449a4
When I try to use domain name instead of IP on github oauth app callback url its giving me an error...
If I change it to:
http://github.com/login/oauth/authorize?response_type=code&redirect_uri=http%3A%2F%2F**XYZIP**%3A3000%2Fauth%2Fgithub%2Fcallback&scope=user%3Aemail&client_id=34940ae24cfd171d449a4
Then it will work but because of different callback URL in oauth it will show me mismatch callback URL.
Basically I am calling from react app front end and node JS back end and passport-git-hub that is in back-end
What am I doing wrong?
This is expected behaviour. When you login through a third party auth service They will call THEIR service and redirect to your service with a session key.
So, what happens is.
There is a Login button, user clicks it
It redirects to google/github/facebook login page where user puts the username and password and presses login.
If user authenticated it generates a session key and sends that session key with additional info(for example profile) to your callback page.
Your callback deserializes the request and generates the user session and profile object and such.
When you open your route passport middleware checks if the session is there, if it's there goes to next() otherwise sends some error as response.
Maybe I got the question completely wrong but this is some generalised flow.

How to handle expired sessions in NodeJs

I'm using Express and Passport.js in my project. I handle login and logout users. But, if the user does not logout, i don't handle expired session. I want to handle expired session or i want to access current session list in the server. Are there any methods for this?

How to renew session in CouchDB

I am using COUCHDB built in Session API in my application. I now want to renew the session as every user logs in, also i do not want to give a long expiry time to the session.
I don't really understand your question. It doesn't make sense that you want to "renew the session as every user logs in".
The whole idea of a session is that it's a per-user-login session. Each user who logs in should trigger a POST /_session request to your CouchDB server, that will respond with an AuthSession cookie which is then what you send back in subsequent requests and that's your session cookie.
The next user who logs in should generate another POST /_session which will create a new session cookie for that user. So there's no renewal as every user logs in.
Now, the expiry on the session is set by the timeout setting in the [couch_httpd_auth] and defaults to 10 minutes. If you want it shorter than that then adjust that setting in your local.ini
So, finally, if you ever want to explicitly remove the session, eg. from a "logout" button, then you do that by sending a DELETE /_session request.

Resources