Download the PHP package iphpjs/socialite without Composer
On this page you can find all versions of the php package iphpjs/socialite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package socialite
Socialite
Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, You can easily use it in any PHP project. 中文文档
This tool now supports platforms such as Facebook, GitHub, Google, LinkedIn, Outlook, QQ, Tapd, Alipay, Taobao, Baidu, DingTalk, Weibo, WeChat, Douyin, Feishu, Douban, WeWork, Tencent Cloud.
- Requirement
- Installation
- Usage
- Configuration
- Custom app name
- Extends custom provider
- Platform
- Alipay
- DingTalk
- Douyin
- Baidu
- Feishu
- Taobao
- Some Skill
- Scopes
- Redirect URL
- State
- Redirect with
state
parameter - Validate the callback
state
- Additional parameters
- User interface
- Standard user api:
- Get raw response from OAuth API
- Get the token response when you use userFromCode()
- Get user with access token
- Enjoy it! :heart:
- Reference
- PHP 扩展包开发
- License
Requirement
Installation
Usage
Users just need to create the corresponding configuration variables, then create the authentication application for each platform through the tool, and easily obtain the access_token and user information for that platform. The implementation logic of the tool is referred to OAuth2 documents of major platforms for details.
The tool is used in the following steps:
- Configurate platform config
- Use this tool to create a platform application
- Let the user redirect to platform authentication
- The server receives a Code callback from the platform, and uses the Code to exchange the user information on the platform (including access_token).
Packages created for Laravel users are easier to integrate: overtrue/laravel-socialite
authorize.php
:
callback.php
:
Configuration
Each create uses the same configuration keys: client_id
, client_secret
, redirect
.
Example:
Custom app name
You can use any name you like as the name of the application, such as foo
, and set provider using provider
key:
Extends custom provider
You can create application from you custom provider easily,you have to ways to do this:
-
Using custom creator: As shown in the following code, the service provider name is defined for the Foo application, but the tool itself does not support it, so use the creator
extend()
to create an instance of the service provider as a closure function. - Using provider:
👋🏻 Your custom provider class must be implements of
Overtrue\Socialite\Contracts\ProviderInterface
.
then set provider
with the class name:
Platform
Different platforms have different configuration methods, so please check the platform Settings you are using.
Alipay
You must have the following configuration.
Only RSA2 personal private keys are supported, so stay tuned if you want to log in with a certificate.
DingTalk
Follow the documentation and configure it like following.
Note: It only supported QR code access to third-part websites. i.e exchange for user information(opendid, unionid and nickname)
Douyin
Note: using the Douyin create that if you get user information directly using access token, set up the openid first. the openid can be obtained by code when access is obtained, so call
userFromCode()
automatically configured for you openid, if calluserFromToken()
first callwithOpenId()
Baidu
You can choose the form you want display by using withDisplay()
.
- page
- popup
- dialog
- mobile
- tv
- pad
popup
mode is the default setting with display. basic
is the default with scopes.
Feishu
Some simple way to use by internal app mode and config app_ticket.
Taobao
You can choose the form you want display by using withView()
.
web
mode is the default setting with display. user_info
is the default with scopes.
We support Open Platform Third-party Platform webpage authorizations on behalf of Official Account.
You just need input your config like below config. Official Accounts authorizations only doesn't need.
Some Skill
Scopes
Before redirecting the user, you may also set "scopes" on the request using the scopes()
method. This method will overwrite all existing scopes:
Redirect URL
You may also want to dynamically set redirect_uri
,you can use the following methods to change the redirect_uri
URL:
State
Your app can use a state parameter for making sure the response belongs to a request initiated by the same user, therefore preventing cross-site request forgery (CSFR) attacks. A CSFR attack occurs when a malicious attacker tricks the user into performing unwanted actions that only the user is authorized to perform on a trusted web application, and all will be done without involving or alerting the user.
Here's the simplest example of how providing the state can make your app more secure. in this example, we use the session ID as the state parameter, but you can use whatever logic you want to create value for the state.
Redirect with state
parameter
Validate the callback state
Once the user has authorized your app, the user will be redirected back to your app's redirect_uri. The OAuth server will return the state parameter unchanged. Check if the state provided in the redirect_uri matches the state generated by your app:
Read more about state
parameter
Additional parameters
To include any optional parameters in the request, call the with()
method with an associative array:
User interface
Standard user api:
You can fetch the user attribute as a array keys like these:
Or using the method:
Get raw response from OAuth API
The $user->getRaw()
method will return an array of the API raw response.
Get the token response when you use userFromCode()
The $user->getTokenResponse()
method will return an array of the get token(access token) API response.
Note: This method only return a valid array when you use
userFromCode()
, else will return null because useuserFromToken()
have no token response.
Get user with access token
Enjoy it! :heart:
Reference
- Alipay - 用户信息授权
- DingTalk - 扫码登录第三方网站
- Google - OpenID Connect
- Github - Authorizing OAuth Apps
- Facebook - Graph API
- Linkedin - Authenticating with OAuth 2.0
- 微博 - OAuth 2.0 授权机制说明
- QQ - OAuth 2.0 登录QQ
- 腾讯云 - OAuth2.0
- 微信公众平台 - OAuth文档
- 微信开放平台 - 网站应用微信登录开发指南
- 微信开放平台 - 代公众号发起网页授权
- 豆瓣 - OAuth 2.0 授权机制说明
- 抖音 - 网站应用开发指南
- 飞书 - 授权说明
- Tapd - 用户授权说明
PHP 扩展包开发
想知道如何从零开始构建 PHP 扩展包?
请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》
License
MIT
All versions of socialite with dependencies
symfony/http-foundation Version ^5.0
guzzlehttp/guzzle Version ~6.0|~7.0
ext-json Version *
symfony/psr-http-message-bridge Version ^2.0
ext-openssl Version *