Download the PHP package sun-asterisk/php-auth without Composer
On this page you can find all versions of the php package sun-asterisk/php-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-auth
Tech Standard PHP Auth
🌟 Introduction
Sun* Auth is a library designed to provide authentication and authorization features for web/mobile applications. It is built using modern technologies and provides a range of features that make it easy to integrate into existing applications.
One of the key reasons for using Sun* Auth is its ease of use. It provides a simple library that makes it easy to add authentication and authorization to any application. Additionally, it is designed to be highly customizable, allowing developers to tailor it to their specific needs.
Using Sun Auth saves time and effort for developers, as we do not have to independently write and test complex authentication and authorization features. Additionally, Sun Auth provides a simple and easy-to-understand library that makes it easy to integrate into existing web/mobile applications.
Some of the features provided by Sun* Auth include user registration and login, password reset and recovery.
- 🔌 Installation
- Laravel
- Lumen
- Other
- 🔎 Usage
- Configure Auth guard
- Injection dependencies use JWT
- Injection dependencies use Session
- Login
- Logout
- Register
- Forgot password
- Refresh token
- Social Login custom
- ⚡ Architecture
- Login
- Logout
- Register
- Forgot password
- Refresh token
- Social Login custom
🔌 Installation
Require the package via Composer:
Laravel
Add the service provider to the providers array in the config/app.php config file as follows:
Publish the configuration file:
Lumen
Configuration
Other
Configuration
Review the configuration file:
Detail
Usage
We will take an example of usage in Laravel.
Configure Auth guard
Inside the config/auth.php file you will need to make a few changes to configure
Add auth:api middleware to routes that require login authentication
Injection dependencies use JWT
Injection dependencies use Session
Login:
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
username | string | true | username for user |
password | string | true | password for user |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
refresh_token | string | true | refresh_token for user get access_token |
access_token | string | true | access_token for user logged |
token_type | string | true | token_type for user logged |
expires_at | integer | true | expires_at for user logged |
Usage with JWT
Detail
Usage with Session
Detail
Example
Logout
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
Authorization | Bearer | true | access_token for authenticate |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
N/A | N/A | N/A | return code 204 - noContent |
Usage with JWT
Detail
Usage with Session
Detail
Example
Register
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
username | string | true | username for user |
password | string | true | password for user |
string | true | email for user |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
id | integer | true | id for user |
username | string | true | username for user |
string | true | email for user |
Usage with JWT
Detail
Usage with Session
Detail
If do you want after register, user will authenticated, Please set true for argument $setGuard as bellow
Example:
Forgot-password
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
string | true | email for user |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
ok | boolean | false | status for the request |
type | string | false | type of the request |
Make postForgotPassword function as the following:
Detail
Make confirm function as the following:
Detail
Make newPassword function as the following:
Detail
Example
Verify
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
token | string | true | Get token from email |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
ok | boolean | false | status for the request |
New Password
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
password | string | true | password for user |
token | string | true | token from user's email |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
ok | boolean | false | status for the request |
type | string | false | type of the request |
Refresh token
- Parameters
Request Field | Field Type | Required | Field Desc |
---|---|---|---|
refresh_token | string | true | refresh_token for user get access_token |
- Responses
Response Field | Field Type | Required | Field Desc |
---|---|---|---|
refresh_token | string | true | refresh_token for user get access_token |
access_token | string | true | access_token for user logged |
token_type | string | true | token_type for user logged |
expires_at | integer | true | expires_at for user logged |
Make Refresh function the following:
Example
Social Login custom
Login With Google
To use you need to install the socialiteproviders/google package via composer:
Add configuration to config/services.php
Update config enabled_social is true to config/sun-asterisk.php
config/sun-asterisk.php
Detail
routes/web.php
Detail
Architecture
Architecture Login
Workflow
Explain
Interface
-
Validator
-
Find item by attribute
-
Compare hash password
- Generate accessToken & refreshToken from jwt
Method login will return an array
$itemArr
is array of object user model. We can custom by callback function as follows
BTW: Also we can change the sql query for the login flow as follows
Architecture Logout
Workflow
Explain
-
Setting Guard to service provider
-
Create method logout in SunGuard
- Invalidate token and refreshToken
Architecture Register
Workflow
Explain
Interface
-
Validator
-
Hash Password
- Insert params to database
Method register will return an array
Custom register
You can changes or validate attributes as following
Architecture Forgot password
Workflow
Explain
Interface
-
Verify Email
-
Generate token
-
Verify token
- Change password
Architecture Refresh token
Workflow
Explain
Interface
-
Decode refresh token
-
Compare exp time of the refresh token
-
Verify user exists
-
Revoke all access token
- Re generate access token
Method refresh will return an array
Architecture Social Login custom
Workflow
Explain
Interface
-
Redirect
- Callback
All versions of php-auth with dependencies
illuminate/database Version ^8.0|^9.0|^10.0
illuminate/support Version ^8.0|^9.0|^10.0
illuminate/http Version ^8.0|^9.0|^10.0
illuminate/routing Version ^8.0|^9.0|^10.0
illuminate/contracts Version ^8.0|^9.0|^10.0
illuminate/validation Version ^8.0|^9.0|^10.0
firebase/php-jwt Version ^6.3
socialiteproviders/manager Version ^4.3