Download the PHP package javaabu/efaas-socialite without Composer
On this page you can find all versions of the php package javaabu/efaas-socialite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download javaabu/efaas-socialite
More information about javaabu/efaas-socialite
Files in javaabu/efaas-socialite
Package efaas-socialite
Short Description eFaas Provider for Laravel Socialite
License MIT
Homepage https://github.com/Javaabu/EFaas-Socialite
Informations about the package efaas-socialite
eFaas Laravel Socialite
Laravel Socialite Provider for eFaas.
Note: Current version of this package is based on eFaas Documentation version 2.2
- eFaas Laravel Socialite
- Requirements
- Installation
- Add configuration to your
.env
file - Publishing the config file
- Publishing migrations
- Usage
- Enabling PKCE
- Logging out the eFaas User
- Using eFaas One-tap Login
- Implementing Front Channel Single Sign Out
- Implementing Back Channel Single Sign Out
- Authenticating from mobile apps
- Changing the eFaas login prompt behaviour
- Available Methods for eFaas Provider
- Available Methods and Public Properties for eFaas User
- Changing the eFaas request scopes
- Getting eFaas data from eFaas User object
- Available eFaas data fields
- Scope: efaas.openid
- Scope: efaas.profile
- Scope: efaas.email
- Scope: efaas.mobile
- Scope: efaas.birthdate
- Scope: efaas.photo
- Scope: efaas.work_permit_status
- Scope: efaas.passport_number
- Scope: efaas.country
- Scope: efaas.permanent_address
- Testing
- Changelog
- Contributing
- Security
- Credits
- License
Requirements
This package requires the following:
- Laravel 6.0 or higher
- PHP 7.4 or higher
- ext-openssl PHP extension
Installation
For Laravel 6.0+, you can install the package via composer
:
For Laravel 5.6, use version 1.x
Add configuration to your .env
file
Add the following config to your .env
file
Publishing the config file
Optionally you can also publish the config file to config/efaas.php
:
This is the default content of the config file:
Publishing migrations
This package ships with the migrations for an efaas_sessions
table which can be used to implement back channel logout. You can publish these migrations using the following Artisan command:
After publishing the migrations, you can run them:
Usage
Note: A demo implementation of this package is available here.
You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed): Refer to the Official Social Docs for more info.
Warning: If you get 403 Forbidden
error when your Laravel app makes requests to the eFaas authorization endpoints,
request NCIT to whitelist your server IP.
and in your callback handler, you can access the user data like so. Remember to save the user's id_token
and sid
(session id).
Enabling PKCE
By default, this package has PKCE disabled. To enable PKCE, use the enablePKCE()
method in both your redirect call and
the callback handler.
Logging out the eFaas User
In your Laravel logout redirect, redirect with the provider logOut()
method using the id token saved during login
Note: Since the id_token
can be very long, you might run into nginx errors when redirecting. To fix this you can
add the following to your nginx config. More
info here.
Using eFaas One-tap Login
This package will automatically add an /efaas-one-tap-login endpoint to your web routes which will redirect to eFaas with the eFaas login code.
Sometimes you may wish to customize the routes defined by the Efaas Provider. To achieve this, you first need to ignore
the routes registered by Efaas Provider by adding EfaasProvider::ignoreRoutes
to the register method of your
application's AppServiceProvider
:
Then, you may copy the routes defined by Efaas Provider in its routes file to your application's routes/web.php file and modify them to your liking:
Implementing Front Channel Single Sign Out
First, during login, in your efaas callback handler method, save the users sid
(session ID) to your session.
Then, in your single sign out controller handler method, first retrieve the logout token's sid
using the eFaas provider's getLogoutSid()
method. The method will return null
if the provided logout token is invalid. You can then compare the saved sid
in your current session with the retrieved sid
and logout the user if they match.
Implementing Back Channel Single Sign Out
For Back Channel Logout, you will need to use Laravel's database
session driver and the provided efaas_sessions
migration.
During login, save the user's sid
(session ID) using the eFaas provider's sessionHandler()
:
Then, in your single sign out controller handler method, first retrieve the logout token's sid
using the eFaas provider's getLogoutSid()
method. The method will return null
if the provided logout token is invalid. You can then use the eFaas provider's sessionHandler()
to logout all laravel sessions that match the sid
.
Authenticating from mobile apps
To authenticate users from mobile apps, redirect to the eFaas login screen through a Web View on the mobile app.
Then intercept the code
(authorization code) from eFaas after they redirect you back to your website after logging in
to eFaas.
Once your mobile app receives the auth code, send the code to your API endpoint.
You can then get the eFaas user details from your server side using the auth code as follows. Remember to use the stateless()
option as the redirect had originated outside of your server:
After you receive the eFaas user, you can then issue your own access token or API key according to whatever authentication scheme you use for your API.
Changing the eFaas login prompt behaviour
The eFaas login prompt behaviour can be customized by modifying the prompt option on your redirect request
The available prompt options are:
Option | Description |
---|---|
login |
Forces the user to enter their credentials on that request, regardless of whether the user is already logged into eFaas. |
none |
Opposite of the login option. Ensures that the user isn't presented with any interactive prompt. If the request can't be completed silently by using single-sign on, the Microsoft identity platform returns an interaction_required error. |
consent |
Triggers the OAuth consent dialog after the user signs in, asking the user to grant permissions to the app. |
select_account |
Interrupts the single sign-on, providing account selection experience listing all the accounts either in session or any remembered account or an option to choose to use a different account altogether |
Available Methods for eFaas Provider
Available Methods and Public Properties for eFaas User
Changing the eFaas request scopes
By default, this package adds all available scopes to the eFaas redirect. You can modify the default scopes by publishing the package config file and changing the scopes. To customize the scopes on a per request basis, you can override the scopes during the redirect.
Getting eFaas data from eFaas User object
Available eFaas data fields
Different data is associated with different scopes. By default, all scopes are included, so you should be able to get all the data fields.
Scope: efaas.openid
Field | Type | Description | Example |
---|---|---|---|
sub |
string |
Unique user key assigned to the user | 178dedf2-581b-4b48-9d73-770f302751dc |
Scope: efaas.profile
Field | Type | Description | Example |
---|---|---|---|
first_name |
string |
First name of the user | Mariyam |
middle_name |
string |
Middle name of the user | Ahmed |
last_name |
string |
Last name of the user | Rasheed |
first_name_dhivehi |
string |
First name of the user in Dhivehi (Maldivians only) | މަރިޔަމް |
middle_name_dhivehi |
string |
Middle name of the user in Dhivehi (Maldivians only) | އަހުމަދު |
last_name_dhivehi |
string |
Last name of the user in dhivehi (Maldivians only) | ރަޝީދު |
gender |
string |
Gender of the user | M / F |
idnumber |
string |
Identification number of the user - National ID number for Maldivians - Work permit number for work permit holders - Passport number for other foreigners |
A000111 / WP941123 / LA110011 |
verified |
bool |
Indicates if the user is verified | True / False |
verification_type |
string |
Type of verification taken by the user | biometric / in-person / NA |
last_verified_date |
Carbon |
The last date when the user was verified either using biometrics or by visiting an eFaas verification counter. | 6/26/2019 9:18:11 AM |
user_type_description |
string |
Indicates the type of user | Maldivian / Work Permit Holder / Foreigner |
updated_at |
Carbon |
The last date when the user information was updated | 6/15/2023 2:12:38 PM |
Scope: efaas.email
Field | Type | Description | Example |
---|---|---|---|
email |
string |
Email of the user | [email protected] |
Scope: efaas.mobile
Field | Type | Description | Example |
---|---|---|---|
mobile |
string |
Mobile number of the user | 9074512 |
country_dialing_code |
string |
Dialing code of the registered number | +960 |
Scope: efaas.birthdate
Field | Type | Description | Example |
---|---|---|---|
birthdate |
string |
Date of birth of the user | 12/20/1990 |
Scope: efaas.photo
Field | Type | Description | Example |
---|---|---|---|
photo |
string |
Photo of the user | https://efaas-api egov.mv/user/photo |
Scope: efaas.work_permit_status
Field | Type | Description | Example |
---|---|---|---|
is_workpermit_active |
bool |
Boolean indicating if the work permit is active (only applicable to work permit holders) | true / false |
Scope: efaas.passport_number
Field | Type | Description | Example |
---|---|---|---|
passport_number |
string |
Passport number of the user | LA110011 |
Scope: efaas.country
Field | Type | Description | Example |
---|---|---|---|
country_name |
string |
Name of the country of the user | Maldives |
country_code |
int |
ISO 3-digit code | 462 |
country_code_alpha3 |
string |
ISO alpha3 code | MDV |
country_dialing_code |
string |
Dialing code of the country | +960 |
Scope: efaas.permanent_address
Field | Type | Description | Example |
---|---|---|---|
permanent_address |
EfaasAddress |
Permanent address of the user | Given below |
Here are the fields of the EfaasAddress
object:
Field | Type | Example |
---|---|---|
AddressLine1 |
string |
Blue Light |
AddressLine2 |
string |
`` |
Road |
string |
Road Name |
AtollAbbreviation |
string |
K |
AtollAbbreviationDhivehi |
string |
ކ |
IslandName |
string |
Male |
IslandNameDhivehi |
string |
މާލެ |
HomeNameDhivehi |
string |
ބުލޭ ލައިޓް |
Ward |
string |
Maafannu |
WardAbbreviationEnglish |
string |
M |
WardAbbreviationDhivehi |
string |
މ |
Country |
string |
Maldives |
CountryISOThreeDigitCode |
string |
462 |
CountryISOThreeLetterCode |
string |
MDV |
The EfaasAddress
class also has the following methods:
Testing
You can run the tests with
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Javaabu Pvt. Ltd.
- Arushad Ahmed (@dash8x)
- Mohamed Jailam
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of efaas-socialite with dependencies
ext-openssl Version *
laravel/socialite Version ^5.15
illuminate/support Version ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
lcobucci/jwt Version ^4.3 || ^5.0
lcobucci/clock Version ^2.0 || ^3.0
strobotti/php-jwk Version ^1.4
phpseclib/phpseclib Version ^3.0.39