incalculable-shoe-63378
07/28/2023, 12:47 AM/self-service/verification/browser
.
Then, the user will get an email and with a link. This link looks like this <http://localhost:4433/self-service/verification?code=779655&flow=6c502039-27a6-4f09-b20d-445c10757962>
. When a user clicks this link, the user is redirected to my custom UI, <http://localhost:5173/verification/confirm?flow=6c502039-27a6-4f09-b20d-445c10757962>
. At this point, I only have the flow id.
How can I find the original CSRF cookie that was used to initiate this flow when I first called /self-service/verification/browser
?
I need the original CSRF cookie because:
1. I need to make a GET request to <http://localhost:4433/self-service/verification/flows?id=${flowId}>
to retrieve the code for the verification and this requires a CSRF cookie. I understand it is also in the email but this way I can automatically populate the code text field.
2. I need to make a POST request to <http://localhost:4433/self-service/verification/flows?id=${flowId}>
to submit the code and verify the user email address.
Thanks!proud-plumber-24205
07/28/2023, 7:43 AMcredentials: include
when making the call with fetch
to Ory. This will include all cookies scoped to this domain to Ory.lemon-apartment-14887
07/28/2023, 8:43 AMproud-plumber-24205
07/28/2023, 8:58 AMlemon-apartment-14887
07/28/2023, 9:04 AM<https://mydomain.dev/kratos/self-service/verification?code=065133&flow=f205b76b-18e8-4014-97cf-45910eef185c>
When the user clicks the link, they get a response 303 and are redirected to the UI URL from the kratos-config, The flow query param stays in place after the redirect to the UI, but the code query param disappears.
The user is redirected to:
<https://mydomain.ui.dev/kratos/self-service/verification?flow=f205b76b-18e8-4014-97cf-45910eef185c>
I really wish I could preserve the code query paramproud-plumber-24205
07/28/2023, 9:15 AMlemon-apartment-14887
07/28/2023, 10:33 AMincalculable-shoe-63378
07/29/2023, 12:15 AMcredentials: 'include'
. To access them you can use the following:
javascript:
export async function GET(request) {
try {
const allCookies = request.cookies.getAll();
const cookieString = allCookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
const flowId = request.url.searchParams.get('flowId');
const response = await fetch(`<http://localhost:4433/self-service/verification/flows?id=${flowId}>`, {
headers: {
'Cookie': cookieString
}
});
} catch (error) {
console.error('Error occurred:', error);
return new Response(`Internal Server Error: ${error}`, { status: 500 });
}
}
incalculable-shoe-63378
07/29/2023, 12:21 AMcsrf_token_csrf_token_82b119fa58a0a1cb6faa9738c1d0dbbf04fcc89a657b7beb31fcde400ced48ab
. How was this generated and how can I get this value?proud-plumber-24205
07/31/2023, 7:08 AMcredentials: "include"
on client-side web applications and it will be included in the request.
For the second csrf token you need to get it from the response body of the flow. https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#csrf-errorsincalculable-shoe-63378
08/10/2023, 10:34 PMcsrf_token
but not the csrf_cookie
. If I understand correctly, the csrf_cookie
is a cookie that is set in the browsers cookie storage automatically when we make a call that initialises a flow of some kind to the Ory Kratos server.
In order to make subsequent calls for the flow, we need to provide the csrf_cookie
in the cookies value for all calls going forward that are related to the same flow id.
Right now, I have it hardcoded to look for a cookie with this name: csrf_token_csrf_token_82b119fa58a0a1cb6faa9738c1d0dbbf04fcc89a657b7beb31fcde400ced48ab
. I do not think hard coding to look for this name is the proper way.
• How is this name generated? Is it dynamic or is it always going to be this exact name?
• What is the proper procedure to find this cookie? What if there are other csrf_token_csrf_token_...
cookies in my browser storage?
Example: When a user clicks the link in the email for email verification, the user is redirected to my custom UI. At this point, we do not have access to any of the HTTP calls from before (do we?). Therefore, I do not have access to the cookies that were used in the calls before. I need to look into the browser storage to find the cookies.proud-plumber-24205
08/11/2023, 6:19 AMfetch
just add the credentials: include
property and the cookies will be automatically included in the request. With axios you can do the same axios.get(<a url>, { withCredentials: true });
incalculable-shoe-63378
08/14/2023, 8:44 PM