gray-shoe-60285
08/30/2023, 11:05 AMoicd-client-ts
(via react-oidc-context
).
Currently we are having some issues with obtaining the Authorization Code form our Oauth server after email and password submission using Ory Elements. I'm concerned this is perhaps due to our misunderstanding of role played by the Ory Session Cookie.
In our current login flow, once the correct email and password is entered the users client gets a Ory Session Cookie. At this point in the code we're at the // login successful
point still on the /login
page:
const submitLoginFlow = (values: UpdateLoginFlowBody) =>
ory
.updateLoginFlow({
flow: String(loginFlow?.id),
updateLoginFlowBody: values,
})
.then(() => {
// login successful
})
.catch((err) => ...
At this point we assumed that we needed to redirect to our authorisation endpoint /oauth2/auth
on our issuer https://auth.ourdomain.com. Is it correct that as they have the Ory Session Cookie at this point, the authorisation endpoint will be able to identify the user and issue the Authorisation Code? Then redirect to out redirect URI?
Another option we have see is to have the above code snippet always receive a 422
, similar to this section in the ory docs where the error contains a redirect_browser_to
string, which would be the Authorisation Endpoint? I can only see this example used however for a native app? This may make more sense for us as the point we are reaching in our login code snippet // login successful
isn't the end of the flow we need - i.e. we still need the access and refresh token.
Once we are back from the Oauth authorisation endpoint we would log out of the Ory session (not needing the Ory Session Cookie) and maintain the users 'logged in' status by periodically refreshing the access token.
Is our current understanding correct? And is either of these approaches advisable for the flow were describing?
Any help would be really appreciated, thanks!limited-photographer-61008
08/30/2023, 11:52 AM422
error case. err.response.data
will contain a redirect_browser_to
value.limited-photographer-61008
08/30/2023, 11:54 AMgray-shoe-60285
08/30/2023, 12:49 PM422
and where can we set this err.response.data
object?limited-photographer-61008
08/30/2023, 1:13 PMcatch
block e.g.
if (err.response?.status === 422) {
const { redirect_browser_to: redirectUrl } =
browserLocationChangeRequiredResponseSchema.parse(err.response?.data);
return redirect(redirectUrl, {
headers: getSetCookieResponseHeaders(err.response.headers),
status: 303,
});
}
Though if possible, I’d submit the form using a regular browser form submit instead of updateLoginFlow
. Then the browser will take care of the redirect, cookies, etc.gray-shoe-60285
08/30/2023, 3:58 PMlimited-photographer-61008
08/30/2023, 4:28 PMlimited-photographer-61008
08/30/2023, 4:29 PMgray-shoe-60285
08/30/2023, 5:54 PMlimited-photographer-61008
08/30/2023, 6:24 PMgray-shoe-60285
08/30/2023, 6:38 PMlimited-photographer-61008
08/30/2023, 7:21 PM