Download the PHP package tobento/app-user without Composer
On this page you can find all versions of the php package tobento/app-user. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/app-user
More information about tobento/app-user
Files in tobento/app-user
Package app-user
Short Description User support for the app with authentication and authorization.
License MIT
Homepage https://www.tobento.ch
Informations about the package app-user
App User
User support for the app with authentication and authorization.
Table of Contents
- Getting Started
- Requirements
- Documentation
- App
- User Boot
- User Config
- User Repositories And Factories
- User Authentication And Authenticator
- Retrieve Current User
- Retrieve Authenticated User
- Authenticate User
- Unauthenticate User
- Acl Boot
- Adding Roles
- Adding Rules
- Authorize User By Permission
- Authorize User By Role
- Http User Error Handler Boot
- Middleware
- User Middleware
- Authentication Middleware
- Authentication With Middleware
- Authenticated Middleware
- Unauthenticated Middleware
- Verified Middleware
- Verify Permission Middleware
- Verify Route Permission Middleware
- Verify Role Middleware
- Authenticator
- Identity Authenticator
- Attributes Authenticator
- User Verifier
- User Permission Verifier
- User Role Verifier
- User Role Area Verifier
- Token Authenticator
- Token Verifier
- Token Password Hash Verifier
- Token Payload Verifier
- Token Storage
- Null Storage
- In Memory Storage
- Repository Storage
- Session Storage
- Token Transport
- Cookie Transport
- Header Transport
- Events
- Console
- Acl Roles Command
- Acl Rules Command
- Delete Expired Tokens Command
- Migration
- Role Permissions Action
- Learn More
- Different Authentication Per Routes
- Password Hashing
- User Channel Verification
- App User Bundles
- Credits
Getting Started
Add the latest version of the app user project running this command.
Requirements
- PHP 8.0 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
User Boot
The user boot does the following:
- installs and loads user config file
- user and role repositories implementation based on config
- adds middleware for authentication and authorization based on config
User Config
The configuration for the user is located in the file at the default App Skeleton config location.
User Repositories And Factories
The following repositories and factories are available as defined in the config file. The default repository implementation uses the as the storage, defined in the file, which is the file storage by default:
You may check out the Repository Interface to learn more about it.
User Authentication And Authenticator
The following authentication and authenticator interfaces are available as defined in the config file by default.
Retrieve Current User
The current user will be available by the after the process of the defined in the config file.
Retrieve Authenticated User
The authenticated user will be available by the after the process of the defined in the config file.
Authenticate User
There are many ways to authenticate a user depending on your config file configuration.
General authentication workflow:
You may use an authenticator to authenticate a user:
See Identity Authenticator - Login Controller Example for instance.
Unauthenticate User
To unauthenticate a user call the method from the :
Acl Boot
The acl boot does the following:
- implements acl interface and set roles
The acl boot gets booted automatically by the User Boot!
You may check out the Acl Service to learn more about it.
Adding Roles
The acl boot will add all roles found from the . You can add roles by the following ways:
Using a migration
Then Install The Migration using the app migration.
Using In Memory Storage
You may use the In Memory Storage instead of the default defined in the config file:
You may verify roles by the Verify Role Middleware.
Adding Rules
By default, no rules are added. You might add rules by the following ways:
Using the app
Using the acl boot
Permissions will be verified by the Verify Permission Middleware.
Check out the Rules to learn more about it.
Authorize User By Permission
There are several ways to authorize a user to access resources by checking its permission.
You may check out the Acl - Permissions section to learn more about it.
Using the acl
Using the user
Using middleware
Use the Verify Permission Middleware to verify permission on routes.
Authorize User By Role
Using the acl
Using the user
Using middleware
Use the Verify Role Middleware to verify role on routes.
Http User Error Handler Boot
The http user error handler boot handles any user specific exceptions such as:
Adding the boot:
You may create a custom Error Handler or add an Error Handler With A Higher Priority of as defined on the .
Middleware
User Middleware
The middleware will ensure that there is always a user available from the request attributes. Furthermore, it sets the current acl user.
Code snippet from the middleware process method:
Authentication Middleware
The middleware will try to authenticate the user on every request by using the defined token transport(s) to fetch the token from the request which will be authenticated by the token authenticator.
Code snippet from the middleware process method:
Authentication With Middleware
Check out the Different Authentication Per Routes section to learn more about this middleware.
Authenticated Middleware
The middleware protects routes from unauthenticated users.
Unauthenticated Middleware
The middleware protects routes from authenticated users.
Verified Middleware
The middleware protects routes from unverified users.
Check out the User Channel Verification section to learn more about it.
Verify Permission Middleware
The middleware protects routes from users without the defined permission(s). If a user has insufficient permission a will be thrown.
Check out the Http User Error Handler Boot how to handle the exception.
Verify Route Permission Middleware
The middleware protects routes from users without the defined permissions. If a user has insufficient permission a will be thrown.
Check out the Http User Error Handler Boot how to handle the exception.
Verify Role Middleware
The middleware protects routes from users without the defined role(s). If a user has insufficient role a will be thrown.
Check out the Http User Error Handler Boot how to handle the exception.
Authenticator
Identity Authenticator
The identifies the user by the and/or and/or from the request input . Furthermore, it verifies the user password from the request input . You can specify which attributes are allowed for identification and if you want to verify the password.
Login Controller Example
Attributes Authenticator
The identifies the user by the specified user attributes. Unlike the Identity Authenticator this authenticator identifies the user by all attributes.
Login Controller Example
User Verifier
User verifiers may be used to verify certain user attributes while authenticating a user. See Identity Authenticator for instance.
User Permission Verifier
User Role Verifier
User Role Area Verifier
Token Authenticator
The token authenticator is responsible to authenticate the user based on the token. See Authentication Middleware for more detail.
You may add token verifiers in the file to verify certain token payload attributes:
Token Verifier
Token verifiers may be used to verify certain token payload attributes while authenticating a user by token. See Token Authenticator for instance.
Token Password Hash Verifier
The may be used to invalidate tokens if user changes password.
Token Payload Verifier
The may be used to invalidate tokens if the specified payload attribute does not match the given value.
Token Storage
Null Storage
The does not store any token at all. This means you will never be authenticated.
In file:
In Memory Storage
The does store tokens in memory only.
In file:
Repository Storage
The uses the Service Repository Storage to store tokens.
In file:
Delete expired tokens
You may call the method to delete all expired tokens:
Session Storage
Stores the token in PHP session.
In file:
Make sure you boot the App Http - Session Boot in your app:
Token Transport
Cookie Transport
Stores the authentication token in a cookie.
In file:
Make sure you boot the App Http - Cookies Boot in your app:
Header Transport
Stores the authentication token in a HTTP header.
In file:
Events
Available Events
Event | Description |
---|---|
The event will dispatch after the user authenticated success | |
The event will dispatch after the user unauthenticated success. | |
The event will dispatch after the user is created. | |
The event will dispatch after the user is updated. | |
The event will dispatch after the user is deleted. |
Supporting Events
Simply, install the App Event bundle.
Console
Before using commands, you will need to install the App Console bundle.
Acl Roles Command
List all acl roles:
Acl Rules Command
List all acl rules:
Delete Expired Tokens Command
You may delete expired tokens from token storages supporting it.
You may delete only from specific token storages:
Migration
Role Permissions Action
You may use the to add and remove permissions for roles.
Then Install The Migration using the app migration.
Learn More
Different Authentication Per Routes
First, configure the file and define token storages and transports you wish to use:
Finally, add middleware to your routes:
Another way to is to use a Http - Area Boot for each area "web" and "api" running in its own application.
Password Hashing
Use the defined in the file to hash and verify user passwords.
Basic Usage
The following authenticators use the password hasher to verify the password:
- Identity Authenticator
- Attributes Authenticator
User Channel Verification
Adding verified channels
Removing verified channels
User verified methods
App User Bundles
You may use the following user bundles for your app.
- App User Web - Login, register and more. (Coming soon)
- App User Manager - CRUD for users, roles and permissions. (Coming soon)
- App User Jwt - Authentication via JSON web token support. (Coming soon)
- App User Login Link - Authentication via login link. (Coming soon)
Credits
- Tobias Strub
- All Contributors
- Spiral Framework - For authentication inspiration
All versions of app-user with dependencies
tobento/app Version ^1.0.7
tobento/app-migration Version ^1.0
tobento/app-http Version ^1.0
tobento/app-database Version ^1.0
tobento/app-validation Version ^1.0
tobento/app-country Version ^1.0
tobento/service-config Version ^1.0
tobento/service-user Version ^1.0.1
tobento/service-acl Version ^1.0
tobento/service-clock Version ^1.0
tobento/service-repository Version ^1.0
tobento/service-repository-storage Version ^1.0