All Projects → letsila → Slim3 Jwt Auth Example

letsila / Slim3 Jwt Auth Example

Licence: mit
Server side implementation example of JWT (JSON Web Token) authentication using Slim3

Projects that are alternatives of or similar to Slim3 Jwt Auth Example

Foal
Elegant and all-inclusive Node.Js web framework based on TypeScript. 🚀.
Stars: ✭ 1,176 (+2513.33%)
Mutual labels:  api, jwt, auth
Jwt sessions
XSS/CSRF safe JWT auth designed for SPA
Stars: ✭ 431 (+857.78%)
Mutual labels:  api, jwt, auth
Go Gin Example
An example of gin
Stars: ✭ 4,992 (+10993.33%)
Mutual labels:  api, jwt
Full Stack
Full stack, modern web application generator. Using Flask, PostgreSQL DB, Docker, Swagger, automatic HTTPS and more.
Stars: ✭ 451 (+902.22%)
Mutual labels:  api, jwt
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: ✭ 44 (-2.22%)
Mutual labels:  api, jwt
Koa Vue Notes Api
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and async/await.
Stars: ✭ 342 (+660%)
Mutual labels:  api, jwt
Jwtrefreshtokenbundle
Implements a Refresh Token system over Json Web Tokens in Symfony
Stars: ✭ 425 (+844.44%)
Mutual labels:  api, jwt
Beauty Vuejs Boilerplate
❤️ Real world base Vue.js app. Access/refresh tokens auth, api services, http client, vuex modules
Stars: ✭ 583 (+1195.56%)
Mutual labels:  api, jwt
Think Api
帮助 thinkphp 5 开发者快速、轻松的构建Api🎉🎉🎉
Stars: ✭ 306 (+580%)
Mutual labels:  api, jwt
Go Book Store Api
Go Sample project to understand Mysql CRUD operation with best practises Includes logging, JWT, Swagger and Transactions
Stars: ✭ 18 (-60%)
Mutual labels:  api, jwt
Snake
🐍 一款小巧的基于Go构建的开发框架,可以快速构建API服务或者Web网站进行业务开发,遵循SOLID设计原则
Stars: ✭ 615 (+1266.67%)
Mutual labels:  api, jwt
Fastify Esso
The easiest authentication plugin for Fastify, with built-in support for Single sign-on
Stars: ✭ 20 (-55.56%)
Mutual labels:  jwt, auth
Zoonavigator
Web-based ZooKeeper UI / editor / browser
Stars: ✭ 326 (+624.44%)
Mutual labels:  api, auth
Jwt Auth Guard
JWT Auth Guard for Laravel and Lumen Frameworks.
Stars: ✭ 319 (+608.89%)
Mutual labels:  jwt, auth
Annon.api
Configurable API gateway that acts as a reverse proxy with a plugin system.
Stars: ✭ 306 (+580%)
Mutual labels:  api, auth
Paseto
Platform-Agnostic Security Tokens implementation in GO (Golang)
Stars: ✭ 461 (+924.44%)
Mutual labels:  jwt, auth
Go Base
Go RESTful API Boilerplate with JWT Authentication backed by PostgreSQL
Stars: ✭ 928 (+1962.22%)
Mutual labels:  api, jwt
Api Security Checklist
Checklist of the most important security countermeasures when designing, testing, and releasing your API
Stars: ✭ 16,339 (+36208.89%)
Mutual labels:  api, jwt
Securing Restful Apis With Jwt
How to secure a Nodejs RESTful CRUD API using JSON web tokens?
Stars: ✭ 301 (+568.89%)
Mutual labels:  api, jwt
Node Express Mongodb Jwt Rest Api Skeleton
This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API). Demo of frontend in VueJS here: https://github.com/davellanedam/vue-skeleton-mvp
Stars: ✭ 603 (+1240%)
Mutual labels:  api, jwt

Slim3 JWT authentication example

This is an example of implementation of JWT authentication on the server side, using Slim3. This code can be used in pair with the ionic2 jwt sample a sample code on JWT via an Ionic2 app.

Running locally

  • Clone or download the repository
  • You have to create a database named tokens which should contain a single table named tokens with the following structure:
    CREATE TABLE `tokens` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `value` text,
      `user_id` int(11) DEFAULT NULL,
      `date_created` int(11) DEFAULT NULL,
      `date_expiration` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  • Be sure that your database configuration match the specification under /src/settings.php
  • Check that all is ok by entering into the downloaded repository and launching phpunit using the following command
$ ./vendor/bin/phpunit
  • You should see
OK (4 tests, 8 assertions)
  • You can now launch the server by typing
php -S 0.0.0.0:8080 -t public public/index.php
  • You are ready to send requests to the server. Check /tests/Functional/RoutesTest.php to see what you can do.

Routes

Two routes were created:

  • An authentication route which allows us to get the credentials and the token sent from the client for validation.
$app->post('/authenticate', function (Request $request, Response $response) {
    // ...
})
  • A route which handle a get request for requiring restricted resource to test out our JWT implementation. This route expected that a token is set on the authorisation header of the request. The token will be validated and if it succeed, we return the requested resource to the client.
$app->get('/restricted', function (Request $request, Response $response) {
    // ...
})

Dependencies

We used [firebase/php-jwt] (https://github.com/firebase/php-jwt) for creating and decoding the JSON web token.

Storage

For simplicity sake, users credentials are stored in a JSON file named users.json located at the root of the project. A database containing a single table named tokens allows us to store each token related information. Database connexion is configured inside /src/dependencies.php.

Middleware

We created a middleware under the /src/middleware.php file in order to enable CORS.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].