Eran Evenor
02/24/2026, 6:27 PM/impersonate endpoint returns a new refresh JWT but the SDK doesn't have any way to 'refresh' the session jwt back to the user, currently the only reasonable way to do it is to call RefreshSessionWithRequest with a fake request:
newJWT, err := descopeCli.Management.JWT().Impersonate(ctx, impersonatorID, targetLoginID, false, nil, targetTenantID, 0)
if err != nil { panic(err)}
// build a fake request to extract refresh jwt
fakeJWTRequest, err := http.NewRequestWithContext(ctx, "POST", "<https://api.descope.com>", nil)
if err != nil {
panic(err)
}
dsrCookie := &http.Cookie{
Name: descopeCli.Auth.GetRefreshCookieName()
Value: newJWT,
}
fakeJWTRequest.Header.Add("Cookie", dsrCookie.String())
// if "rotate refresh token" is set, we just lost refreshToken forever
ok, newToken, err := descopeCli.Auth.RefreshSessionWithRequest(fakeJWTRequest, w)
if err != nil {
panic(err)
}
// if not in cookie mode, the client-side SDK sets this one, so we need to clear it
http.SetCookie(w, &http.Cookie{
Domain: "localhost",
Name: descopeCli.Auth.GetSessionCookieName(),
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteStrictMode,
MaxAge: -1,
})
...
if the SDK would have allow me to use the inner provate refreshSession method, and allow to return both session and refresh token, i think i'll be okish (although i still need to sync up all the project configs as the mgmt api doesn't offer any reasonable to query those settings)Eran Evenor
02/24/2026, 6:29 PMChris Carper
02/24/2026, 8:40 PMBhagwanta Yeole
02/24/2026, 9:08 PMBhagwanta Yeole
02/24/2026, 10:25 PMBhagwanta Yeole
02/25/2026, 12:31 AM// If ValidateSessionWithRequest raises an exception, you will need to refresh the session using
if authorized, sessionToken, err := descopeClient.Auth.RefreshSessionWithToken(context.Background(), refreshToken); !authorized {
// unauthorized error
}Eran Evenor
02/25/2026, 4:39 AMBhagwanta Yeole
02/25/2026, 4:48 AMAtharva Joshi
02/25/2026, 5:00 AMAviad Lichtenstadt
02/25/2026, 9:18 PMfunc (auth *authenticationService) RefreshSessionWithTokenAndWriter(ctx context.Context, refreshToken string, w http.ResponseWriter) (bool, *descope.Token, error) {
if refreshToken == "" {
return false, nil, utils.NewInvalidArgumentError("refreshToken")
}
return auth.refreshSession(ctx, refreshToken, w)
}
?Eran Evenor
02/25/2026, 9:19 PMRefreshSession it will probably do most of the heavy liftingEran Evenor
02/25/2026, 9:21 PM