@@ -67,12 +67,19 @@ app.use(
6767 prefix: " /auth" ,
6868 successRedirect: " http://localhost:3000/oauth-success" ,
6969 failureRedirect: " http://localhost:3000/oauth-failure" ,
70- autoProvision: true ,
7170 defaultRole: " ROLE_USER" ,
72- setRefreshCookie: true ,
73- appendTokensInRedirect: false ,
74- includeAuthorities: true ,
75- issueJwt: true ,
71+ onSuccess (info)=> {
72+ const {profile , existingUser ,} = info;
73+ if (existingUser){
74+ return existingUser;
75+ }
76+
77+ // Logic to create new user
78+ reateUser (profile)
79+ },
80+ onfailure (info)=> {
81+ // Logic to be executed onFailure
82+ },
7683 providers: {
7784 google: {
7885 clientID: " GOOGLE_CLIENT_ID" ,
@@ -82,15 +89,6 @@ app.use(
8289 },
8390 },
8491 },
85- cookies: {
86- enabled: true ,
87- name: " AuthRefreshToken" ,
88- httpOnly: true ,
89- secure: false ,
90- sameSite: " Strict" ,
91- maxAge: 7 * 24 * 60 * 60 * 1000 ,
92- path: " /" ,
93- },
9492 twoFA: {
9593 enabled: false ,
9694 prefix: " /auth/2fa" ,
@@ -250,7 +248,6 @@ oauth2: {
250248- ** defaultRole** : Default role assigned to new users.
251249- ** providers** : Supported providers (e.g., Google, GitHub).
252250
253-
254251### ** Two-Factor Authentication**
255252
256253``` javascript
@@ -334,6 +331,7 @@ All endpoints use the configured prefix. Default prefixes shown below:
334331- ** GET** ` /auth/{provider} ` - Initiate OAuth login
335332- ** GET** ` /auth/{provider}/callback ` - OAuth callback
336333- ** GET** ` /auth/error ` - OAuth error redirect
334+ - ** POST** ` /auth/token ` - to get token from temporary code
337335
338336### ** Two-Factor Authentication**
339337
@@ -368,6 +366,15 @@ All endpoints use the configured prefix. Default prefixes shown below:
3683663 . Server processes authentication and auto-creates user if add any logic onSuccess.
3693674 . Server redirects to success URL with tokens as cookies.
3703685 . Subsequent requests use JWT or session authentication.
369+ 6 . After successful provider authentication, the temporary code will be set as a query parameter on the redirect URL.
370+ 7 . Frontend can then trigger ` {prefix}/token ` with a ` POST ` request and payload:
371+
372+ ``` json
373+ {
374+ "code" : " code-from-redirect-url"
375+ }
376+ ```
377+
371378
372379## Logout Behavior
373380
0 commit comments