K
Kinde3mo ago
Ricer

ExpressJS SDK for a MEAN stack web application.

Hi, I'm trying to integrate the SDK into my web application. My backend is written in ExpressJS and my frontend in AngularJS. The authentication flow is as follows: 1) User presses a button to Sign in with Kinde. 2) The user is navigated to the backend via window.location.href = this.api.address + 'kinde/login' 3) A check is made to see if user is authenticated (via await kindeClient.isAuthenticated(req)) 4) If not authenticated, the user is redirected to BACKEND_URL/login via res.redirect('/login') 5) The user then enters the credentials and is redirected back to BACKEND_URL/login This is the case if I enter from BACKEND_URL/login manually, but when I start from the frontend, after entering my credentials in Kinde, I get redirected to the unAuthorisedUrl
6 Replies
Ricer
RicerOP3mo ago
Also, If tried navigating the user from the frontend using angular's HttpClient module, I get "Access to XMLHttpRequest at MY_KINDE_DOMAIN/oauth2/auth?QUERY_PARAMS (redirected from http://192.168.1.220:3000/kinde/login from origin http://localhost:4200 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the request resource" This was done via "this.http.get(${BACKEND_ADDRESS}/kinde/login, { withCredentials: true })"
IkiTg07
IkiTg073mo ago
If I get it well when testing your login logic from the backend it works ok but when trying with the frontend you always get redirected to unauthorisedUrl ?
Ricer
RicerOP3mo ago
Exactly
IkiTg07
IkiTg073mo ago
this is weird. Have you tried to fix the CORS issue using a middleware on your backend to accept requests from your frontend ??
Ricer
RicerOP3mo ago
I did, yes. I've added both http://localhost:4200 and my IP address with port 4200 to the origins, and it didn't work.
IkiTg07
IkiTg073mo ago
Have you tried testing not in a dev environement ?

Did you find this page helpful?