affinidi/laravel-socialite-affinidi
Composer 安装命令:
composer require affinidi/laravel-socialite-affinidi
包简介
Affinidi (affinidi.com) OIDC Provider for Laravel Socialite.
README 文档
README
AUGMENT EXPERIENCES WITH A SAFER, SIMPLER AND MORE PRIVATE WAY TO LOGIN
A paradigm shift in the registration and sign-in process, Affinidi Login is a game-changing solution for developers. With our revolutionary passwordless authentication solution your user's first sign-in doubles as their registration, and all the necessary data for onboarding can be requested during this streamlined sign-in/signup process. End users are in full control, ensuring that they consent to the information shared in a transparent and user-friendly manner. This streamlined approach empowers developers to create efficient user experiences with data integrity, enhanced security and privacy, and ensures compatibility with industry standards.
| Passwordless Authentication | Decentralised Identity Management | Uses Latest Standards |
|---|---|---|
| Offers a secure and user-friendly alternative to traditional password-based authentication by eliminating passwords and thus removing the vulnerability to password-related attacks such as phishing and credential stuffing. | Leverages OID4VP to enable users to control their data and digital identity, selectively share their credentials and authenticate themselves across multiple platforms and devices without relying on a centralised identity provider. | Utilises OID4VP to enhance security of the authentication process by verifying user authenticity without the need for direct communication with the provider, reducing risk of tampering and ensuring data integrity. |
Introduction
This package extends Socialite to enable passwordless authentication with the Affinidi OIDC provider.
Learn more about Laravel Socialite here
Quick Links
- Installation & Usage
- Create Affinidi Login Configuration
- Affinidi Login Integration with Sample Laravel project
- Affinidi Login Integration in Fresh Laravel Project
- Affinidi Login Integration in Existing Laravel Project
Installation & Basic Usage
To get started with Affinidi Socialite, follow these steps:
- Install the Affinidi Socialite package using Composer:
composer require affinidi/laravel-socialite-affinidi
- Add the following configuration to your
config/services.phpfile:
'affinidi' => [
'base_uri' => env('PROVIDER_ISSUER'),
'client_id' => env('PROVIDER_CLIENT_ID'),
'client_secret' => env('PROVIDER_CLIENT_SECRET'),
'redirect' => '/login/affinidi/callback',
],
- Extend the setup of the Affinidi Socialite driver using our helper class in the
boot()function ofapp\Providers\AppServiceProvider.php:
public function boot(): void
{
$socialite = $this->app->make(Factory::class);
// Setup the affinidi driver
\Affinidi\SocialiteProvider\AffinidiSocialite::extend($socialite);
}
Authentication
To authenticate users using an OAuth provider, you will need two routes: one for redirecting the user to the OAuth provider, and another for receiving the callback from the provider after authentication.
The example routes below demonstrate the implementation of both routes:
use Laravel\Socialite\Facades\Socialite;
Route::get('/login/affinidi/redirect', function () {
return Socialite::driver('affinidi')->redirect();
});
Route::get('/login/affinidi/callback', function () {
$user = Socialite::driver('affinidi')->user();
// $user->token
});
Create Affinidi Login Configuration
Create the Login Configuration using Affinidi Dev Portal as illustrated here. You can given name as "Socialite App" and Redirect URIs as per your application specific e.g. "https:///login/affinidi/callback"
Important: Safeguard the Client ID and Client Secret and Issuer; you'll need them for setting up your environment variables. Remember, the Client Secret will be provided only once.
Note: By default Login Configuration will requests only Email VC, if you want to request email and profile VC, you can refer PEX query under (docs\loginConfig.json)[playground\example\docs\loginConfig.json] and execute the below affinidi CLI command to update PEX
affinidi login update-config --id <CONFIGURATION_ID> -f docs\loginConfig.json
Setup & Run application from playground folder
Open the directory playground/example in VS code or your favorite editor
-
Install the dependencies by executing the below command in terminal
composer install -
Create the
.envfile in the sample application by running the following commandcp .env.example .env -
Create Affinidi Login Configuration as mentioned here
-
Update below environment variables in
.envbased on the auth credentials received from the Login Configuration created earlier:PROVIDER_CLIENT_ID="<AUTH.CLIENT_ID>" PROVIDER_CLIENT_SECRET="<AUTH.CLIENT_SECRET>" PROVIDER_ISSUER="<AUTH.CLIENT_ISSUER>"Sample values looks like below
PROVIDER_CLIENT_ID="xxxxx-xxxxx-xxxxx-xxxxx-xxxxx" PROVIDER_CLIENT_SECRET="xxxxxxxxxxxxxxx" PROVIDER_ISSUER="https://yyyy-yyy-yyy-yyyy.apse1.login.affinidi.io" -
Run the application
php artisan serve -
Open the http://localhost:8000/, which displays login page Important: You might error on redirect URL mismatch if you are using
http://127.0.0.1:8000/instead ofhttp://localhost:8000/. -
Click on
Affinidi Loginbutton to initiate OIDC login flow with Affinidi Vault
Integration Affinidi Login - Fresh Laravel Project
If you want to start fresh without any base reference app, then you can follow the below steps
Create Laravel Project
Before creating your first Laravel project, you should ensure that your local machine has PHP and Composer installed.
- You may create a new Laravel project via the Composer
create-projectcommand
composer create-project laravel/laravel example-app
Note: If you enounter any issue on creating project like fileInfo, then you may have enable the fileInfo extension in your php.ini file like below
extension=fileinfo
- After the project has been created, start Laravel's local development server using the Laravel's Artisan CLI
servecommand
cd example-app
php artisan serve
- Once you have started the Artisan development server, your application will be accessible in your web browser at http://localhost:8000
Note: If you encounter an error on generating Key, then execute the below command which updates APP_KEY in your .env file and then run the app
php artisan key:generate
Install Affinidi Socialite Provider
To get started with Socialite, use the Composer package manager to add the package to your project's dependencies
- Install Affinidi Socialite Library
composer require affinidi/laravel-socialite-affinidi
- Open
AppServiceProvider.phpfile underapp\Providers, and bootstrap the Affinidi driver to socialite class inside functionboot(), the code should look like below
public function boot(): void
{
$socialite = $this->app->make(Factory::class);
\Affinidi\SocialiteProvider\AffinidiSocialite::extend($socialite);
}
- Add credentials for the Affinidi OIDC provider, should be placed in your application's
config/services.phpconfiguration file,
'affinidi' => [
'base_uri' => env('PROVIDER_ISSUER'),
'client_id' => env('PROVIDER_CLIENT_ID'),
'client_secret' => env('PROVIDER_CLIENT_SECRET'),
'redirect' => '/login/affinidi/callback',
],
Use Affinidi Provider Inside Controller
- Create
LoginRegisterController.phpfile underapp\Http\Controllers, which has actions to perform normal login, logout, affinidi login and its callback, reference can be found here - Open
routes\web.phpfile and Add Web Routes which invokes the above login controller actions, reference can be found here - Create file
login.blade.phpunderresources\viewsfor adding Affinidi Login button, reference can be found here - Create dashboard
dashboard.blade.phpunderresources\viewsfor displaying the logged in user info, reference can be found here
Run the application
- Run the application
php artisan serve - Open the http://localhost:8000/, which displays login page
Important: You might error on redirect URL mismatch if you are using
http://127.0.0.1:8000/instead ofhttp://localhost:8000/. - Click on
Affinidi Loginbutton to initiate OIDC login flow with Affinidi Vault
Integration Affinidi Login to existing Laravel Project
If you want to integrate Affinidi Login to any existing PHP Laravel Application using socialite, then you can follow the below steps
Install Affinidi Socialite Provider
To get started with Socialite, use the Composer package manager to add the package to your project's dependencies
- Install Affinidi Socialite Library
composer require affinidi/laravel-socialite-affinidi
- Open
AppServiceProvider.phpfile underapp\Providers, and bootrap the affinidi driver to socialite class inside functionboot(), the code should look like below
public function boot(): void
{
$socialite = $this->app->make(Factory::class);
\Affinidi\SocialiteProvider\AffinidiSocialite::extend($socialite);
}
- Add credentials for the Affinidi OIDC provider, should be placed in your application's
config/services.phpconfiguration file,
'affinidi' => [
'base_uri' => env('PROVIDER_ISSUER'),
'client_id' => env('PROVIDER_CLIENT_ID'),
'client_secret' => env('PROVIDER_CLIENT_SECRET'),
'redirect' => '/login/affinidi/callback',
],
-
Create the Login Configuration as per step here
-
Update below environment variables in .env based on the auth credentials obtained from the previous step
PROVIDER_CLIENT_ID="<AUTH.CLIENT_ID>" PROVIDER_CLIENT_SECRET="<AUTH.CLIENT_SECRET>" PROVIDER_ISSUER="<AUTH.CLIENT_ISSUER>"
-
Add the Affinidi Login button in your login page, reference can be found here
-
Use socialite driver as 'affinidi' in route handler / controller, reference controller can be found here
Run the application
- Run the application
php artisan serve - Open the http://localhost:8000/, which displays login page
Important: You might error on redirect URL mismatch if you are using
http://127.0.0.1:8000/instead ofhttp://localhost:8000/. - Click on
Affinidi Loginbutton to initiate OIDC login flow with Affinidi Vault
Call Affinidi APIs
For example, if you want to issue a VC
- Generate Personal access token using command line tool more details here and update .env file with details
VAULT_URL="https://vault.affinidi.com"
API_GATEWAY_URL="https://apse1.api.affinidi.io"
TOKEN_ENDPOINT="https://apse1.auth.developer.affinidi.io/auth/oauth2/token"
PROJECT_ID=""
KEY_ID=""
TOKEN_ID=""
PASSPHRASE=""
PRIVATE_KEY=""
- Set the service config file
'affinidi_tdk' => [
'api_gateway_url' => env('API_GATEWAY_URL'),
'token_endpoint' => env('TOKEN_ENDPOINT'),
'project_Id' => env('PROJECT_ID'),
'private_key' => env('PRIVATE_KEY'),
'token_id' => env('TOKEN_ID'),
'passphrase' => env('PASSPHRASE'),
'key_id' => env('KEY_ID'),
'vault_url' => env('VAULT_URL'),
],
- Code snippet to invoke TDK helper methods by reading config values
$credentials_request =
[
[
"credentialTypeId" => "AnyTcourseCertificateV1R0",
"credentialData" => [
"courseID" => "EMP-IT-AUTOMATION-2939302",
"course" => [
"name" => "IT Automation with Python",
"type" => "Professional Certificate",
"url" => "",
"courseDuration" => "45 Days"
],
"learner" => [
"name" => "",
"email" => "grajesh.c@affinidi.com",
"phone" => ""
],
"achievement" => [
"score" => "100",
"grade" => "A"
],
"courseMode" => "online",
"completionDate" => "08/09/2024"
]
]
];
$apiMethod = '/cis/v1/' . config('services.affinidi_tdk.project_Id') . '/issuance/start';
$data = \Affinidi\SocialiteProvider\AffinidiTDK::InvokeAPI($apiMethod, [
'data' => $credentials_request,
'claimMode' => "TX_CODE"
]);
affinidi/laravel-socialite-affinidi 适用场景与选型建议
affinidi/laravel-socialite-affinidi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 147 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「oauth」 「provider」 「laravel」 「oidc」 「socialite」 「affinidi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 affinidi/laravel-socialite-affinidi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 affinidi/laravel-socialite-affinidi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 affinidi/laravel-socialite-affinidi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WeChat OAuth SDK
Time provider, providing consistent current date, time, datetime and timezone across the request.
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
Library for ORCID web services
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
An Zend Expressive module for loading ZF2 or ZF3 modules.
统计信息
- 总下载量: 147
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-01-10