forked from overtrue/socialite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,141 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
C:37:"PHPUnit\Runner\DefaultTestResultCache":1272:{a:2:{s:7:"defects";a:6:{s:50:"Providers\FeiShuTest::testProviderCanCreateCorrect";i:3;s:50:"Providers\FeiShuTest::testConfigAppAccessTokenWork";i:4;s:90:"Providers\FeiShuTest::testConfigAppAccessTokenWithDefaultModeAndAppTicketWorkInBadResponse";i:3;s:91:"Providers\FeiShuTest::testConfigAppAccessTokenWithDefaultModeAndAppTicketWorkInGoodResponse";i:4;s:71:"Providers\FeiShuTest::testConfigAppAccessTokenWithInternalInBadResponse";i:3;s:72:"Providers\FeiShuTest::testConfigAppAccessTokenWithInternalInGoodResponse";i:4;}s:5:"times";a:9:{s:50:"Providers\FeiShuTest::testProviderCanCreateCorrect";d:0.003;s:57:"Providers\FeiShuTest::testProviderWithInternalAppModeWork";d:0;s:51:"Providers\FeiShuTest::testProviderWithAppTicketWork";d:0;s:50:"Providers\FeiShuTest::testConfigAppAccessTokenWork";d:0.003;s:76:"Providers\FeiShuTest::testConfigAppAccessTokenWithDefaultModeNoAppTicketWork";d:0.003;s:90:"Providers\FeiShuTest::testConfigAppAccessTokenWithDefaultModeAndAppTicketWorkInBadResponse";d:0.002;s:91:"Providers\FeiShuTest::testConfigAppAccessTokenWithDefaultModeAndAppTicketWorkInGoodResponse";d:0;s:71:"Providers\FeiShuTest::testConfigAppAccessTokenWithInternalInBadResponse";d:0;s:72:"Providers\FeiShuTest::testConfigAppAccessTokenWithInternalInGoodResponse";d:0;}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,11 @@ | |
</p> | ||
|
||
|
||
<p align="center">Socialite is an OAuth2 Authentication tool. It is inspired by <a href="https://github.com/laravel/socialite">laravel/socialite</a>, You can easily use it in any PHP project.</p> | ||
<p align="center">Socialite is an OAuth2 Authentication tool. It is inspired by <a href="https://github.com/laravel/socialite">laravel/socialite</a>, You can easily use it in any PHP project. <a href="https://github.com/overtrue/socialite/blob/master/README_CN.md">中文文档</aa></p> | ||
|
||
|
||
|
||
[TOC] | ||
|
||
# Requirement | ||
|
||
|
@@ -78,7 +82,7 @@ $user->getEmail(); // "[email protected]" | |
... | ||
``` | ||
|
||
### Configuration | ||
## Configuration | ||
|
||
Now we support the following sites: | ||
|
||
|
@@ -97,22 +101,22 @@ Example: | |
... | ||
``` | ||
|
||
#### Custom app name | ||
### 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: | ||
|
||
```php | ||
$config = [ | ||
'foo' => [ | ||
'provider' => 'github', // <-- | ||
'provider' => 'github', // <-- provider name | ||
'client_id' => 'your-app-id', | ||
'client_secret' => 'your-app-secret', | ||
'redirect' => 'http://localhost/socialite/callback.php', | ||
], | ||
|
||
// another github app | ||
'bar' => [ | ||
'provider' => 'github', // <-- | ||
'provider' => 'github', // <-- provider name | ||
'client_id' => 'your-app-id', | ||
'client_secret' => 'your-app-secret', | ||
'redirect' => 'http://localhost/socialite/callback.php', | ||
|
@@ -121,16 +125,17 @@ $config = [ | |
]; | ||
``` | ||
|
||
#### Extends custom provider | ||
### Extends custom provider | ||
|
||
You can create application from you custom provider easily,you have to ways to do this: | ||
|
||
1. 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. | ||
|
||
```php | ||
$config = [ | ||
'foo' => [ | ||
'provider' => 'myprovider', // <-- | ||
'provider' => 'myprovider', // <-- provider name | ||
'client_id' => 'your-app-id', | ||
'client_secret' => 'your-app-secret', | ||
'redirect' => 'http://localhost/socialite/callback.php', | ||
|
@@ -173,12 +178,19 @@ $socialite = new SocialiteManager($config); | |
$app = $socialite->create('foo'); | ||
``` | ||
|
||
##### [Alipay](https://opendocs.alipay.com/open/200/105310#s2) | ||
If you want to use `alipay` create, you need set config like below. | ||
|
||
|
||
## Platform | ||
|
||
Different platforms have different configuration methods, so please check the platform Settings you are using. | ||
|
||
### [Alipay](https://opendocs.alipay.com/open/200/105310#s2) | ||
|
||
You must have the following configuration. | ||
```php | ||
... | ||
$config = [ | ||
'alipay' => [ | ||
// the key, pointed by the key value of this array, can also be named as 'app_id' like the official documentation. | ||
// This can also be named as 'app_id' like the official documentation. | ||
'client_id' => 'your-app-id', | ||
|
||
// Please refer to the official documentation, in the official management background configuration RSA2. | ||
|
@@ -188,56 +200,128 @@ If you want to use `alipay` create, you need set config like below. | |
'rsa_private_key' => 'your-rsa-private-key', | ||
|
||
// Be sure to set this value and make sure that it is the same address value as set in the official admin system. | ||
// the key, pointed by the key value of this array, can also be named as 'redirect_url' like the official documentation. | ||
// This can also be named as 'redirect_url' like the official documentation. | ||
'redirect' => 'http://localhost/socialite/callback.php', | ||
], | ||
] | ||
... | ||
]; | ||
|
||
$socialite = new SocialiteManager($config); | ||
|
||
$user = $socialite->create('alipay')->userFromCode('here is auth code'); | ||
|
||
// See this documents "User interface" | ||
$user->getId(); // 1472352 | ||
$user->getNickname(); // "overtrue" | ||
$user->getUsername(); // "overtrue" | ||
$user->getName(); // "安正超" | ||
... | ||
``` | ||
Only RSA2 personal private keys are supported, so stay tuned if you want to log in with a certificate. | ||
|
||
##### [DingTalk](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3) | ||
### [DingTalk](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3) | ||
|
||
Follow the documentation and configure it in the development panel. | ||
Follow the documentation and configure it like following. | ||
|
||
> Note: We only support QR code access to third-part websites. i.e exchange for user information(opendid, unionid and nickname) | ||
> Note: It only supported QR code access to third-part websites. i.e exchange for user information(opendid, unionid and nickname) | ||
```php | ||
... | ||
'dingtalk' => [ | ||
// or 'app_id' | ||
'client_id' => 'your app id', | ||
$config = [ | ||
'dingtalk' => [ | ||
// or 'app_id' | ||
'client_id' => 'your app id', | ||
|
||
// or 'app_secret' | ||
'client_secret' => 'your app secret', | ||
// or 'app_secret' | ||
'client_secret' => 'your app secret', | ||
|
||
// or 'redirect_url' | ||
'redirect' => 'redirect URL' | ||
], | ||
// or 'redirect_url' | ||
'redirect' => 'redirect URL' | ||
] | ||
]; | ||
|
||
$socialite = new SocialiteManager($config); | ||
|
||
$user = $socialite->create('dingtalk')->userFromCode('here is auth code'); | ||
|
||
// See this documents "User interface" | ||
$user->getId(); // 1472352 | ||
$user->getNickname(); // "overtrue" | ||
$user->getUsername(); // "overtrue" | ||
$user->getName(); // "安正超" | ||
... | ||
``` | ||
|
||
##### [Douyin](https://open.douyin.com/platform/doc/OpenAPI-oauth2) | ||
### [Douyin](https://open.douyin.com/platform/doc/OpenAPI-oauth2) | ||
|
||
> 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 call `userFromToken()` first call `withOpenId()` | ||
```php | ||
$config = [ | ||
'douyin' => [ | ||
'client_id' => 'your app id', | ||
|
||
'client_secret' => 'your app secret', | ||
|
||
'redirect' => 'redirect URL' | ||
] | ||
]; | ||
|
||
$socialite = new SocialiteManager($config); | ||
|
||
$user = $socialite->create('douyin')->userFromCode('here is auth code'); | ||
|
||
$user = $socialite->create('douyin')->withOpenId('openId')->userFromToken('here is a access token'); | ||
$user = $socialite->create('douyin')->withOpenId('openId')->userFromToken('here is the access token'); | ||
``` | ||
|
||
|
||
##### [Baidu](https://developer.baidu.com/wiki/index.php?title=docs/oauth) | ||
### [Baidu](https://developer.baidu.com/wiki/index.php?title=docs/oauth) | ||
|
||
You can choose the form you want display by using `withDisplay()`. | ||
|
||
- **page** | ||
- **popup** | ||
- **dialog** | ||
- **mobile** | ||
- **tv** | ||
- **pad** | ||
|
||
```php | ||
create$authUrl = $socialite->driver('baidu')->withDisplay('mobile')->redirect(); | ||
$authUrl = $socialite->create('baidu')->withDisplay('mobile')->redirect(); | ||
|
||
``` | ||
`popup` mode is the default setting with display. `basic` is the default with scopes. | ||
|
||
##### [Taobao](https://open.taobao.com/doc.htm?docId=102635&docType=1&source=search) | ||
### [Feishu](https://open.feishu.cn/document/ukTMukTMukTM/uITNz4iM1MjLyUzM) | ||
|
||
Some simple way to use by internal app mode and config app_ticket. | ||
|
||
```php | ||
$config = [ | ||
'feishu' => [ | ||
// or 'app_id' | ||
'client_id' => 'your app id', | ||
|
||
// or 'app_secret' | ||
'client_secret' => 'your app secret', | ||
|
||
// or 'redirect_url' | ||
'redirect' => 'redirect URL', | ||
|
||
// if you want to use internal way to get app_access_token | ||
// set this key by 'internal' then you already turn on the internal app mode | ||
'app_mode' => 'internal' | ||
] | ||
]; | ||
|
||
$socialite = new SocialiteManager($config); | ||
|
||
$feishuDriver = $socialite->create('feishu'); | ||
|
||
$feishuDriver->withInternalAppMode()->userFromCode('here is code'); | ||
$feishuDriver->withDefaultMode()->withAppTicket('app_ticket')->userFromCode('here is code'); | ||
``` | ||
|
||
### [Taobao](https://open.taobao.com/doc.htm?docId=102635&docType=1&source=search) | ||
|
||
You can choose the form you want display by using `withView()`. | ||
|
||
|
@@ -246,7 +330,7 @@ $authUrl = $socialite->create('taobao')->withView('wap')->redirect(); | |
``` | ||
`web` mode is the default setting with display. `user_info` is the default with scopes. | ||
|
||
##### [WeChat](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/official_account_website_authorization.html) | ||
### [WeChat](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/official_account_website_authorization.html) | ||
|
||
We support Open Platform Third-party Platform webpage authorizations on behalf of Official Account. | ||
|
||
|
@@ -272,10 +356,11 @@ You just need input your config like below config. Official Accounts authorizati | |
... | ||
``` | ||
|
||
## Some Skill | ||
|
||
### Scope | ||
### Scopes | ||
|
||
Before redirecting the user, you may also set "scopes" on the request using the scope method. This method will overwrite all existing scopes: | ||
Before redirecting the user, you may also set "scopes" on the request using the `scopes()` method. This method will overwrite all existing scopes: | ||
|
||
```php | ||
$response = $socialite->create('github') | ||
|
@@ -300,7 +385,7 @@ Your app can use a state parameter for making sure the response belongs to a req | |
|
||
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 | ||
### Redirect with `state` parameter | ||
```php | ||
<?php | ||
session_start(); | ||
|
@@ -319,7 +404,7 @@ $url = $socialite->create('github')->withState($state)->redirect(); | |
return redirect($url); | ||
``` | ||
|
||
#### Validate the callback `state` | ||
### 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: | ||
|
||
|
@@ -343,17 +428,17 @@ $user = $socialite->create('github')->userFromCode($code); | |
|
||
### Additional parameters | ||
|
||
To include any optional parameters in the request, call the with method with an associative array: | ||
To include any optional parameters in the request, call the `with()` method with an associative array: | ||
|
||
```php | ||
$response = $socialite->create('google') | ||
->with(['hd' => 'example.com'])->redirect(); | ||
``` | ||
|
||
|
||
### User interface | ||
## User interface | ||
|
||
#### Standard user api: | ||
### Standard user api: | ||
|
||
```php | ||
$user = $socialite->create('github')->userFromCode($code); | ||
|
@@ -410,11 +495,11 @@ mixed $user->getId(); | |
|
||
``` | ||
|
||
#### Get raw response from OAuth API | ||
### 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() | ||
### Get the token response when you use userFromCode() | ||
|
||
The `$user->getTokenResponse()` method will return an **array** of the get token(access token) API response. | ||
|
||
|
@@ -427,7 +512,9 @@ $accessToken = 'xxxxxxxxxxx'; | |
$user = $socialite->userFromToken($accessToken); | ||
``` | ||
|
||
Enjoy it! :heart: | ||
|
||
|
||
# Enjoy it! :heart: | ||
|
||
# Reference | ||
|
||
|
@@ -448,7 +535,9 @@ Enjoy it! :heart: | |
- [飞书 - 授权说明](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM) | ||
- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093) | ||
|
||
## PHP 扩展包开发 | ||
|
||
|
||
# PHP 扩展包开发 | ||
|
||
> 想知道如何从零开始构建 PHP 扩展包? | ||
> | ||
|
Oops, something went wrong.