Hello Team, After logging in using SSO, the follow...
# ask-a-descoper
a
Hello Team, After logging in using SSO, the following API is called:
https://dev.auth.us.<domain>/v1/auth/refresh?dcs=f&dcr=f
However, we’re receiving a 401 (Unauthorized) response. The SSO flow itself is successful — we’re getting a 200 response from the IDP — but when this refresh API is triggered afterward, it fails with a 401. Could you please advise if there’s any configuration or update required on our side to resolve this? @Mike Hudson @Kenneth Knoll
👀 1
r
Can you share your project id?
m
Hey Rahul its P2rk79RWgfAxiOhEVBEEaNGf0RGR What we experienced is a user with ID: U34yy6J0yDCDel6iG3YCu2O1yXbr going through the login flow but then the token refresh failing. In this case this was a newly provisioned user by JIT - although we have experienced this other times, maybe Arif can give more details on recreation steps if this isn't clear from the info given. The user logged in again after a short delay and everything went smoothly. Not sure if the JIT is related or something in our flow is doing something incorrect
a
@Rahul Rijhwani - So, there are two cases where we face this issue 1) We have set up SSO with JIT provisioning for one of the tenants, where users log in using their email addresses. During the first login attempt, the IDP returns a successful authentication response, and the login flow completes. However, the refresh token API call fails, causing the user to be redirected back to the login page. On the second login attempt, the user is able to sign in successfully. User id - U34yy6J0yDCDel6iG3YCu2O1yXbr project id - P2rk79RWgfAxiOhEVBEEaNGf0RGR Flow - aptly-login-flow 2) We have set up SSO for the domain example.com and example.org. In the authentication flow, we use an email like arif@example.com. When this email is entered, the domain is recognized by SSO, and the user is redirected to the IDP login page. However, the user actually logs in using arif@example.org (different domain), which has a different domain from the configured SSO domain. The IDP login succeeds, and as a result, a new user is created in Descope. After login, the refresh token API call fails with an “unauthorized” error, and the user is redirected back to the login screen. On the next login attempt using arif@example.org, the user can successfully log in, since that user now exists in Descope.
r
Hi @Arif let me go through your use cases and will get back to you soon
🙌 1
a
@Rahul Rijhwani - Any update?
r
Hi @Chris Carper or @Reuven Zabirov can you assist here.
c
Looking at this now @Arif - give us a bit.
Reviewing that user ID shared specifically: • The user came in on 11/3 and was successfully authenticated (11/3 13:58 my time) ◦ JWT issued after flow execution (11/3 13:59 my time) • The user's session was later refreshed successfully. ◦ 11/3 14:24 my time • Then on 11/4 around 1:13 my time ◦ The JWT does not match user error was seen (which would show up as a 401), but it was during the execution of the
aptly-end-impersonation
flow. • 11/4 around 8:04 the user is again successfully authenticated and several refreshes over the next few hours.
Is it possible this user got kicked to an area where that impersonation flow runs unintentionally?
For the second item, we treat
.org
and
.com
users the same when it comes to unique identifiers, so we'll always treat these as separate users; however, this could relate to the tenant SSO domain, if you have customers who use both, it's worth adding both their
.org
and
.com
domains to the SSO domains configuration for their tenant.
I see you do have custom domain configured, but the tokens are still stored on the response body, and your refresh token is not stored within cookies. With the advanced config of having refresh token enabled and the session inactivity timer enabled, it may be worth switching over to storing the refresh token as a cookie here.
a
This case happened only first time when user try to login with SSO. so After logging in using SSO, the following API is called right after the flow complete:
https://dev.auth.us.<domain>/v1/auth/refresh?dcs=f&dcr=f
However, we’re receiving a 401 (Unauthorized) response. And due to that we got redirected to the login page again. Is there anything needs to configure in flow?
c
@Arif, can you share the code from your page? Do you check if
isLoading
is still true before rendering? CC: @Tal Kapitolnik @Reuven Zabirov for 👀 in your timezone.
a
function App() {
const { isAuthenticated, isSessionLoading, sessionToken } = useSession();
const { isUserLoading, user } = useUser();
const { setStorageItem } = useLocalStorageHook<string>();
const isLoading = useMemo(
() => isSessionLoading || isUserLoading,
[isSessionLoading, isUserLoading],
);
const getUserRoute = useCallback(() => {
if (!isAuthenticated || !sessionToken) {
if (window.location.pathname !== "/") {
setStorageItem("nextUrl", window.location.pathname);
}
return authRoute;
}
if (!user?.userTenants || user?.userTenants?.length === 0) {
return noTenantRoute;
}
return router;
}, [isAuthenticated, sessionToken, user]);
if (isLoading) {
return (
<ThemeProvider>
<CustomLoader />
</ThemeProvider>
);
}
Yes, we are using an isLoading flag before render. is there anything needs to update over there?
@Chris Carper - Please look at this user id - U34yy6J0yDCDel6iG3YCu2O1yXbr Which face the issue on first login with SSO. And even every user who did not exist in descope and try to login with SSO, then first time after completing the flow it redirected to the login page again.
r
if the
/refresh
is failing seems to be something wrong with the refresh token. can you share a HAR file reproducing the issue? you can also DM it to me so it will be discreet.
a
@Reuven Zabirov - Have shared HAR file in DM
r
From the HAR file i see that the response from the /refresh says "Missing JWT for refresh session" it means that the JWT is not sent along with this request. I would ensure that when the flow ends - to check that the DS and DSR are set correctly (either as cookies or as localStorage) if the flow does not end succesfully (could happen with SSO if the user is not redirected correctly to the flow to end it properly - we should see a LoginFlowDone event in audit log) the tokens are not set. i would start by: 1. reproducing the SSO flow, seeing if you have DS & DSR at the end of the flow 2. if not - check the last /next request in the network - there might be an issue with the cookie set, and error in the console or something else 3. if there is a DS & DSR either in cookies or in localStorage, we need to check if they are cleared before the /refresh request, might be because of your backend sending over a 400/401 response to the FE?
a
@Reuven Zabirov - Okay let me check.
@Reuven Zabirov - We have verified that token are getting stored correctly after the flow complete. One of the our API was giving an 401, so we have resolved that issue. But still refresh token API is giving a 401 with same error "Missing JWT for refresh session", but user is now able to login successfully without any issue. Anything wrong with the flow or configuration?
r
no, might be an SDK issue. are you using the latest SDK version?
a
Currently we are using this version - "@descope/react-sdk": "^2.13.2"
r
try upgrading the SDK and let me know if that helps
🙌 1