Download the PHP package sebk/small-swoft-auth without Composer
On this page you can find all versions of the php package sebk/small-swoft-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sebk/small-swoft-auth
More information about sebk/small-swoft-auth
Files in sebk/small-swoft-auth
Package small-swoft-auth
Short Description Swoft jwt auth based on small-orm
License GPL-3.0-only
Informations about the package small-swoft-auth
sebk/small-swoft-auth
Jwt auth for Swoft based on small-orm
Include a controller superclass to simple implement token support in your controllers and link with voters to manage user rigths
Install
Create your Swoft project : http://swoft.io/docs/2.x/en/quick-start/install.html
Install dependencies
Require Swoft Voter package (https://github.com/sebk69/small-swoft-auth) :
Documentation
Parameter
In base.php, register AuthManagerService :
In app.php, register app.user according to your app to tell AuthManager to request you're app user:
Implement UserModelInterface
You're application user model must implement UserModelInterface. (In this example, password stored via md5 hash for simplicity. Don't use md5 hash, prefere SHA-256 hash or more for security reasons) :
Implement your voters
See https://github.com/sebk69/small-voter for config and implementation
Implement login
Implement your controllers
To protect your controller :
- use AuthMiddleware of swoft/auth
- your controller must extends TokenSecuredController abstract class
Additionnaly, you can protect a route via specific rules of your app by using voter on your controller object using denyAccessUnlessGranted method :
Here is a controller example :
Usage : login request
Here is a AuthController implementing a login action :
To test it, use your favorit rest app on :
It will respond you something like :
Or a 401 response if wrong login or password
Now, to access protected route, use Authorization header with the token of login response.
For our customer list route, use :
If success, the server will return a 200 status code and if token is wrong or expired, it wil return a 401 status code.
All versions of small-swoft-auth with dependencies
swoft/auth Version ~2.0.0
sebk/small-orm-swoft Version 1.*
sebk/small-orm-forms Version 1.*
sebk/swoft-voter Version 1.*