Skip to content

Instantly share code, notes, and snippets.

@timogoosen
Last active September 2, 2022 13:24
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 timogoosen/2f67b264baa3fb0de44888de8e2510f3 to your computer and use it in GitHub Desktop.
Save timogoosen/2f67b264baa3fb0de44888de8e2510f3 to your computer and use it in GitHub Desktop.
JWT For Dummies

Login with username/email and password:


$ curl --silent -d '{"email":"user@example.com","password":"SUPERSECRETPASSWORD"}' -H "Content-Type: application/json" -X POST http://vue-spa-laravel-vue-spa.localhost/api/login | jq '.'
{
  "token": "REDACTED",
  "token_type": "bearer",
  "expires_in": 86400
}


$ export TOKEN="REDACTED"


Now interact with API using that token:


$ curl --silent -H "Content-Type: application/json" -H "Authorization: Bearer ${TOKEN}" http://vue-spa-laravel-vue-spa.localhost/api/user | jq '.'
{
  "id": 1,
  "name": "Timo Goosen",
  "email": "user@example.com",
  "email_verified_at": null,
  "created_at": "2022-09-01T14:29:46.000000Z",
  "updated_at": "2022-09-01T14:29:46.000000Z",
  "photo_url": "https://www.gravatar.com/avatar/fa0c70fe72300c0a07b49baa09c2f6dc.jpg?s=200&d=https%3A%2F%2Fui-avatars.com%2Fapi%2FTimo+Goosen"
}

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