Skip to content

Instantly share code, notes, and snippets.

@yaroofie
Last active February 11, 2023 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroofie/87a9fa8cfa10cc31521d0d9ff345e004 to your computer and use it in GitHub Desktop.
Save yaroofie/87a9fa8cfa10cc31521d0d9ff345e004 to your computer and use it in GitHub Desktop.

laravel sanctum on postman :

  • add this to your .env
SESSION_DOMAIN=yourdomain.com
SANCTUM_STATEFUL_DOMAINS=yourdomain.com
SESSION_SECURE_COOKIE=false
  • then add your domain to cookie section of postman
  • Cookie section
  • then
  • Add your domain
  • then hit add domain
  • after that you can [optional] add your postman envirement variables
  • Add postman env variables
  • then with a simple post request scripting you can save the xsrf-token cookie value
  • as a postman envirement variable like this
  • save xsrf-token to env variable
  • don't worry I won't make you type it out:
pm.test("Setting xsrf_token env vairable", function () {
    let cookie = pm.response.cookies.get('XSRF-TOKEN');
    if(cookie) pm.environment.set('xsrf-token',cookie);
    else {
        let header = pm.response.headers.find(h => h.key == 'Set-Cookie' && h.value.startsWith('XSRF-TOKEN'));
        cookie = header?.value.substring(header?.value.indexOf("=") + 1, header?.value.indexOf("%3D"));
        pm.environment.set('xsrf-token',cookie);
    }
});
  • then on your web routes you must add x-xsrf-token header
  • add-x-xsrf-token-header

this should work ,at least it works for me, I hope it helps you, peace out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment