{"id":13405403,"url":"https://github.com/overtrue/socialite","last_synced_at":"2025-05-13T00:16:08.311Z","repository":{"id":40331151,"uuid":"47127359","full_name":"overtrue/socialite","owner":"overtrue","description":"Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, you can easily use it without Laravel.","archived":false,"fork":false,"pushed_at":"2024-12-31T10:33:58.000Z","size":415,"stargazers_count":1327,"open_issues_count":8,"forks_count":240,"subscribers_count":37,"default_branch":"4.x","last_synced_at":"2025-05-13T00:15:57.465Z","etag":null,"topics":["alipay","baidu","dingtalk","douban","douyin","facebook","feishu","google","laravel","linkedin","login","oauth","oauth2","oauth2-authentication","qq","social-login","socialite","taobao","wechat","weibo"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/overtrue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["overtrue"]}},"created_at":"2015-11-30T15:21:29.000Z","updated_at":"2025-05-09T10:52:28.000Z","dependencies_parsed_at":"2024-12-03T01:04:29.900Z","dependency_job_id":"88a814e6-24b5-41b6-a54e-0c5e46369e15","html_url":"https://github.com/overtrue/socialite","commit_stats":{"total_commits":268,"total_committers":49,"mean_commits":5.469387755102041,"dds":"0.32835820895522383","last_synced_commit":"5afc6f823a2bb6ce8cf0db20fd39a7f3e762152c"},"previous_names":[],"tags_count":111,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fsocialite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fsocialite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fsocialite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Fsocialite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/overtrue","download_url":"https://codeload.github.com/overtrue/socialite/tar.gz/refs/heads/4.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843225,"owners_count":21972874,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alipay","baidu","dingtalk","douban","douyin","facebook","feishu","google","laravel","linkedin","login","oauth","oauth2","oauth2-authentication","qq","social-login","socialite","taobao","wechat","weibo"],"created_at":"2024-07-30T19:02:01.118Z","updated_at":"2025-05-13T00:16:08.278Z","avatar_url":"https://github.com/overtrue.png","language":"PHP","funding_links":["https://github.com/sponsors/overtrue","https://developer.paypal.com/docs/log-in-with-paypal/","https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/"],"categories":["PHP","类库"],"sub_categories":["OAuth"],"readme":"# Socialite\n\nSocialite 是一个 [OAuth2](https://oauth.net/2/) 认证工具。 它的灵感来源于 [laravel/socialite](https://github.com/laravel/socialite) ， 你可以很轻易的在任何 PHP 项目中使用它。[英文文档](/README_EN.md)\n\n[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/overtrue/socialite?style=flat-square)](https://github.com/overtrue/socialite/releases)\n[![GitHub License](https://img.shields.io/github/license/overtrue/socialite?style=flat-square)](https://github.com/overtrue/socialite/blob/master/LICENSE)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/overtrue/socialite?style=flat-square)](https://packagist.org/packages/overtrue/socialite)\n\n[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)\n\n该工具现已支持平台有：Facebook，Github，Google，Linkedin，Outlook，QQ，TAPD，支付宝，淘宝，百度，钉钉，微博，微信，抖音，飞书，Lark，豆瓣，企业微信，腾讯云，Line，Gitee，Coding。\n\n如果你喜欢我的项目并想支持我，[点击这里 :heart:](https://github.com/sponsors/overtrue)\n\n## 版本要求\n\nPHP \u003e= 8.0.2\n\n## 安装\n\n```shell\ncomposer require \"overtrue/socialite\" -vvv\n```\n\n## 使用指南\n\n用户只需要创建相应配置变量，然后通过工具为各个平台创建认证应用，并轻松获取该平台的 access_token 和用户相关信息。工具实现逻辑详见参照各大平台 OAuth2 文档。\n\n工具使用大致分为以下几步：\n\n1. 配置平台设置\n2. 创建对应平台应用\n3. 让用户跳转至平台认证\n4. 服务器收到平台回调 Code，使用 Code 换取平台处用户信息（包括 access_token）\n\n为 Laravel 用户创建的更方便的整合的包： [overtrue/laravel-socialite](https://github.com/overtrue/laravel-socialite)\n\n`authorize.php`: 让用户跳转至平台认证\n\n```php\n\u003c?php\n\nuse Overtrue\\Socialite\\SocialiteManager;\n\n$config = [\n    'github' =\u003e [\n        'client_id'     =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect'      =\u003e 'http://localhost/socialite/callback.php',\n    ],\n];\n\n$socialite = new SocialiteManager($config);\n\n$url = $socialite-\u003ecreate('github')-\u003eredirect();\n\nreturn redirect($url);\n```\n\n`callback.php`:\n\n```php\n\u003c?php\n\nuse Overtrue\\Socialite\\SocialiteManager;\n\n$config = [\n    'github' =\u003e [\n        'client_id' =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect' =\u003e 'http://localhost/socialite/callback.php',\n    ],\n];\n\n$socialite = new SocialiteManager($config);\n\n$code = request()-\u003equery('code');\n\n$user = $socialite-\u003ecreate('github')-\u003euserFromCode($code);\n\n$user-\u003egetId();        // 1472352\n$user-\u003egetNickname();  // \"overtrue\"\n$user-\u003egetUsername();  // \"overtrue\"\n$user-\u003egetName();      // \"安正超\"\n$user-\u003egetEmail();     // \"anzhengchao@gmail.com\"\n...\n```\n\n## 配置\n\n为每个平台设置相同的键值对后就能开箱即用：`client_id`, `client_secret`, `redirect`.\n\n示例：\n\n```php\n$config = [\n  'weibo' =\u003e [\n    'client_id'     =\u003e 'your-app-id',\n    'client_secret' =\u003e 'your-app-secret',\n    'redirect'      =\u003e 'http://localhost/socialite/callback.php',\n  ],\n  'facebook' =\u003e [\n    'client_id'     =\u003e 'your-app-id',\n    'client_secret' =\u003e 'your-app-secret',\n    'redirect'      =\u003e 'http://localhost/socialite/callback.php',\n  ],\n];\n```\n\n### 自定义应用名\n\n你可以使用任意你喜欢的名字对每个平台进行命名，比如说 `foo`， 采用别名的方法后需要在配置中多设置一个 `provider` 键，这样才能告诉工具包如何正确找到你想要的程序：\n\n```php\n$config = [\n  // 为 github 应用起别名为 foo\n    'foo' =\u003e [\n        'provider'    =\u003e 'github',  // \u003c-- provider name\n        'client_id'   =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect'    =\u003e 'http://localhost/socialite/callback.php',\n    ],\n\n    // 另外一个名字叫做 bar 的 github 应用\n    'bar' =\u003e [\n        'provider'    =\u003e 'github',  // \u003c-- provider name\n        'client_id'   =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect'    =\u003e 'http://localhost/socialite/callback.php',\n    ],\n\n    //...\n];\n\n$socialite = new SocialiteManager($config);\n\n$appFoo = $socialite-\u003ecreate('foo');\n$appBar = $socialite-\u003ecreate('bar');\n```\n\n### 扩展自定义服务提供程序\n\n你可以很容易的从自定义的服务提供中创建应用，只需要遵循如下两点：\n\n1. 使用自定义创建器\n\n   如下代码所示，为 foo 应用定义了服务提供名，但是工具本身还未支持，所以使用创建器 `extend()`，以闭包函数的形式为该服务提供创建一个实例。\n\n```php\n$config = [\n    'foo' =\u003e [\n        'provider' =\u003e 'myprovider',  // \u003c-- 一个工具还未支持的服务提供程序\n        'client_id' =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect' =\u003e 'http://localhost/socialite/callback.php',\n    ],\n];\n\n$socialite = new SocialiteManager($config);\n\n$socialite-\u003eextend('myprovider', function(array $config) {\n    return new MyCustomProvider($config);\n});\n\n$app = $socialite-\u003ecreate('foo');\n```\n\n1. 使用服务提供类\n\n\u003e [!IMPORTANT]  \n\u003e \n\u003e 👋🏻 你的自定义服务提供类必须实现 `Overtrue\\Socialite\\Contracts\\ProviderInterface` 接口\n\n```php\nclass MyCustomProvider implements \\Overtrue\\Socialite\\Contracts\\ProviderInterface\n{\n    //...\n}\n```\n\n接下来为 `provider` 设置该类名让工具可以找到该类并实例化：\n\n```php\n$config = [\n    'foo' =\u003e [\n        'provider'    =\u003e MyCustomProvider::class,  // \u003c-- 类名\n        'client_id'   =\u003e 'your-app-id',\n        'client_secret' =\u003e 'your-app-secret',\n        'redirect'    =\u003e 'http://localhost/socialite/callback.php',\n    ],\n];\n\n$socialite = new SocialiteManager($config);\n$app = $socialite-\u003ecreate('foo');\n```\n\n## 平台\n\n不同的平台有不同的配置方法，为了确保工具的正常运行，所以请确保你所使用的平台的配置都是如期设置的。\n\n### [支付宝](https://opendocs.alipay.com/open/200/105310#s2)\n\n请按如下方式配置\n\n```php\n$config = [\n  'alipay' =\u003e [\n    // 这个键名还能像官方文档那样叫做 'app_id'\n    'client_id' =\u003e 'your-app-id',\n\n    // 请根据官方文档，在官方管理后台配置 RSA2\n    // 注意： 这是你自己的私钥\n    // 注意： 不允许私钥内容有其他字符\n    // 建议： 为了保证安全，你可以将文本信息从磁盘文件中读取，而不是在这里明文\n    'rsa_private_key' =\u003e 'your-rsa-private-key',\n\n    // 确保这里的值与你在服务后台绑定的地址值一致\n    // 这个键名还能像官方文档那样叫做 'redirect_url'\n    'redirect' =\u003e 'http://localhost/socialite/callback.php',\n\n    // 沙箱模式接入地址见 https://opendocs.alipay.com/open/220/105337#%E5%85%B3%E4%BA%8E%E6%B2%99%E7%AE%B1\n    'sandbox' =\u003e false,\n  ]\n  ...\n];\n\n$socialite = new SocialiteManager($config);\n\n$user = $socialite-\u003ecreate('alipay')-\u003euserFromCode('here is auth code');\n\n// 详见文档后面 \"User interface\"\n$user-\u003egetId();        // 1472352\n$user-\u003egetNickname();  // \"overtrue\"\n$user-\u003egetUsername();  // \"overtrue\"\n$user-\u003egetName();      // \"安正超\"\n...\n```\n\n本工具暂时只支持 RSA2 个人私钥认证方式。\n\n### [钉钉](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3)\n\n如文档所示\n\n\u003e 注意：该工具仅支持 QR code 连接到第三方网站，用来获取用户信息（opeid， unionid 和 nickname）\n\n```php\n$config = [\n  'dingtalk' =\u003e [\n      // or 'app_id'\n      'client_id' =\u003e 'your app id',\n\n      // or 'app_secret'\n      'client_secret' =\u003e 'your app secret',\n\n      // or 'redirect_url'\n      'redirect' =\u003e 'redirect URL'\n  ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$user = $socialite-\u003ecreate('dingtalk')-\u003euserFromCode('here is auth code');\n\n// 详见文档后面 \"User interface\"\n$user-\u003egetId();        // 1472352\n$user-\u003egetNickname();  // \"overtrue\"\n$user-\u003egetUsername();  // \"overtrue\"\n$user-\u003egetName();      // \"安正超\"\n...\n```\n\n### [抖音](https://open.douyin.com/platform/doc/OpenAPI-oauth2)\n\n\u003e 注意： 使用抖音服务提供的时候，如果你想直接使用 access_token 获取用户信息时，请先设置 openid。 先调用 `withOpenId()` 再调用 `userFromToken()`\n\n```php\n$config = [\n  'douyin' =\u003e [\n      'client_id' =\u003e 'your app id',\n\n      'client_secret' =\u003e 'your app secret',\n\n      'redirect' =\u003e 'redirect URL'\n  ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$user = $socialite-\u003ecreate('douyin')-\u003euserFromCode('here is auth code');\n\n$user = $socialite-\u003ecreate('douyin')-\u003ewithOpenId('openId')-\u003euserFromToken('here is the access token');\n```\n\n### [头条](https://open.douyin.com/platform/resource/docs/develop/permission/toutiao-or-xigua/OAuth2.0/)\n\n\u003e 注意： 使用`头条`服务提供的时候，如果你想直接使用 access_token 获取用户信息时，请先设置 openid。 先调用 `withOpenId()` 再调用 `userFromToken()`\n\n```php\n$config = [\n  'toutiao' =\u003e [\n    'client_id' =\u003e 'your app id',\n    'client_secret' =\u003e 'your app secret',\n    'redirect' =\u003e 'redirect URL'\n  ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$user = $socialite-\u003ecreate('toutiao')-\u003euserFromCode('here is auth code');\n$user = $socialite-\u003ecreate('toutiao')-\u003ewithOpenId('openId')-\u003euserFromToken('here is the access token');\n```\n\n### [西瓜](https://open.douyin.com/platform/resource/docs/develop/permission/toutiao-or-xigua/OAuth2.0/)\n\n\u003e 注意： 使用`西瓜`服务提供的时候，如果你想直接使用 access_token 获取用户信息时，请先设置 openid。 先调用 `withOpenId()` 再调用 `userFromToken()`\n\n```php\n$config = [\n  'xigua' =\u003e [\n    'client_id' =\u003e 'your app id',\n    'client_secret' =\u003e 'your app secret',\n    'redirect' =\u003e 'redirect URL'\n  ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$user = $socialite-\u003ecreate('xigua')-\u003euserFromCode('here is auth code');\n$user = $socialite-\u003ecreate('xigua')-\u003ewithOpenId('openId')-\u003euserFromToken('here is the access token');\n```\n\n### [百度](https://developer.baidu.com/wiki/index.php?title=docs/oauth)\n\n其他配置没啥区别，在用法上，可以很轻易的选择重定向登录页面的模式，通过 `withDisplay()`\n\n- **page：**全屏形式的授权页面 (默认)，适用于 web 应用。\n- **popup:** 弹框形式的授权页面，适用于桌面软件应用和 web 应用。\n- **dialog:** 浮层形式的授权页面，只能用于站内 web 应用。\n- **mobile:** Iphone/Android 等智能移动终端上用的授权页面，适用于 Iphone/Android 等智能移动终端上的应用。\n- **tv:** 电视等超大显示屏使用的授权页面。\n- **pad:** IPad/Android 等智能平板电脑使用的授权页面。\n\n```php\n$authUrl = $socialite-\u003ecreate('baidu')-\u003ewithDisplay('mobile')-\u003eredirect();\n\n```\n\n`popup` 模式是工具内默认的使用模式。`basic` 是默认使用的 scopes 值。\n\n### [飞书](https://open.feishu.cn/document/ukTMukTMukTM/uITNz4iM1MjLyUzM)\n\n通过一些简单的方法配置  app_ticket 就能使用内部应用模式\n\n```php\n$config = [\n    'feishu' =\u003e [\n        // or 'app_id'\n        'client_id' =\u003e 'your app id',\n\n        // or 'app_secret'\n        'client_secret' =\u003e 'your app secret',\n\n        // or 'redirect_url'\n        'redirect' =\u003e 'redirect URL',\n\n        // 如果你想使用使用内部应用的方式获取 app_access_token\n        // 对这个键设置了 'internal' 值那么你已经开启了内部应用模式\n        'app_mode' =\u003e 'internal'\n    ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$feishuDriver = $socialite-\u003ecreate('feishu');\n\n$feishuDriver-\u003ewithInternalAppMode()-\u003euserFromCode('here is code');\n$feishuDriver-\u003ewithDefaultMode()-\u003ewithAppTicket('app_ticket')-\u003euserFromCode('here is code');\n```\n\n### [Lark](https://open.larksuite.com/document/ukTMukTMukTM/uITNz4iM1MjLyUzM)\n\n通过一些简单的方法配置  app_ticket 就能使用内部应用模式\n\n```php\n$config = [\n    'lark' =\u003e [\n        // or 'app_id'\n        'client_id' =\u003e 'your app id',\n\n        // or 'app_secret'\n        'client_secret' =\u003e 'your app secret',\n\n        // or 'redirect_url'\n        'redirect' =\u003e 'redirect URL',\n\n        // 如果你想使用使用内部应用的方式获取 app_access_token\n        // 对这个键设置了 'internal' 值那么你已经开启了内部应用模式\n        'app_mode' =\u003e 'internal'\n    ]\n];\n\n$socialite = new SocialiteManager($config);\n\n$larkDriver = $socialite-\u003ecreate('lark');\n\n$larkDriver-\u003ewithInternalAppMode()-\u003euserFromCode('here is code');\n$larkDriver-\u003ewithDefaultMode()-\u003ewithAppTicket('app_ticket')-\u003euserFromCode('here is code');\n```\n\n### [淘宝](https://open.taobao.com/doc.htm?docId=102635\u0026docType=1\u0026source=search)\n\n其他配置与其他平台的一样，你能选择你想要展示的重定向页面类型通过使用 `withView()`\n\n```php\n$authUrl = $socialite-\u003ecreate('taobao')-\u003ewithView('wap')-\u003eredirect();\n```\n\n`web` 模式是工具默认使用的展示方式， `user_info` 是默认使用的 scopes 范围值。\n\n### [微信](https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Official_Accounts/official_account_website_authorization.html)\n\n我们支持开放平台代表公众号进行第三方平台网页授权。\n\n你只需要像下面这样输入你的配置。官方账号不需要授权。\n\n```php\n...\n[\n    'wechat' =\u003e\n        [\n            'client_id'   =\u003e 'client_id',\n            'client_secret' =\u003e 'client_secret',\n            'redirect'    =\u003e 'redirect-url',\n\n            // 开放平台 - 第三方平台所需\n            'component' =\u003e [\n                // or 'app_id', 'component_app_id' as key\n                'id' =\u003e 'component-app-id',\n                // or 'app_token', 'access_token', 'component_access_token' as key\n                'token' =\u003e 'component-access-token',\n            ]\n        ]\n],\n...\n```\n\n### [Coding](https://coding.net/help/openapi#oauth)\n\n您需要额外配置 `team_url` 为您的团队域名，例如：\n\n```php\n$config = [\n    'coding' =\u003e [\n        'team_url' =\u003e 'https://{your-team}.coding.net',\n        'client_id' =\u003e 'your app id',\n        'client_secret' =\u003e 'your app secret',\n        'redirect' =\u003e 'redirect URL',\n    ]\n];\n```\n\n### [PayPal](https://developer.paypal.com/docs/log-in-with-paypal/)\n\n您可能需要设置responseType，可以使用`withResponseType`函数进行设置，默认是`code` 还可以设置为`id_token` 或`code` \u0026 `id_token`\n\n\u003e \u003chttps://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/\u003e\n\n```php\n$config = [\n    'paypal' =\u003e [\n        'client_id'     =\u003e 'AT******************',\n        'client_secret' =\u003e 'EK**************',\n        'sandbox'      =\u003e false,\n        'redirect_url'=\u003e\"nativexo://paypalpay\",\n    ],\n];\n```\n\n## 其他一些技巧\n\n### Scopes\n\n在重定向用户之前，您还可以使用 `scopes()` 方法在请求上设置 “范围”。此方法将覆盖所有现有的作用域：\n\n```php\n$response = $socialite-\u003ecreate('github')\n                -\u003escopes(['scope1', 'scope2'])-\u003eredirect();\n```\n\n### Redirect URL\n\n你也可以动态设置' redirect_uri '，你可以使用以下方法来改变 `redirect_uri` URL:\n\n```php\n$url = 'your callback url.';\n\n$socialite-\u003eredirect($url);\n// or\n$socialite-\u003ewithRedirectUrl($url)-\u003eredirect();\n```\n\n### State\n\n你的应用程序可以使用一个状态参数来确保响应属于同一个用户发起的请求，从而防止跨站请求伪造 (CSFR) 攻击。当恶意攻击者欺骗用户执行不需要的操作 (只有用户有权在受信任的 web 应用程序上执行) 时，就会发生 CSFR 攻击，所有操作都将在不涉及或警告用户的情况下完成。\n\n这里有一个最简单的例子，说明了如何提供状态可以让你的应用程序更安全。在本例中，我们使用会话 ID 作为状态参数，但是您可以使用您想要为状态创建值的任何逻辑。\n\n### 带着 `state` 参数的重定向\n\n```php\n\u003c?php\nsession_start();\n\n$config = [\n    //...\n];\n\n// Assign to state the hashing of the session ID\n$state = hash('sha256', session_id());\n\n$socialite = new SocialiteManager($config);\n\n$url = $socialite-\u003ecreate('github')-\u003ewithState($state)-\u003eredirect();\n\nreturn redirect($url);\n```\n\n### 检验回调的 `state`\n\n一旦用户授权你的应用程序，用户将被重定向回你的应用程序的 redirect_uri。OAuth 服务器将不加修改地返回状态参数。检查 redirect_uri 中提供的状态是否与应用程序生成的状态相匹配：\n\n```php\n\u003c?php\nsession_start();\n\n$state = request()-\u003equery('state');\n$code = request()-\u003equery('code');\n\n// Check the state received with current session id\nif ($state != hash('sha256', session_id())) {\n    exit('State does not match!');\n}\n$user = $socialite-\u003ecreate('github')-\u003euserFromCode($code);\n\n// authorized\n```\n\n[查看更多关于 `state` 参数的文档](https://auth0.com/docs/protocols/oauth2/oauth-state)\n\n### 其他的一些参数\n\n要在请求中包含任何可选参数，调用 `with()` 方法传入一个你想要设置的关联数组：\n\n```php\n$response = $socialite-\u003ecreate('google')\n                    -\u003ewith(['hd' =\u003e 'example.com'])-\u003eredirect();\n```\n\n## User interface\n\n### 标准的 user api\n\n```php\n$user = $socialite-\u003ecreate('github')-\u003euserFromCode($code);\n```\n\n```json\n{\n  \"id\": 1472352,\n  \"nickname\": \"overtrue\",\n  \"name\": \"安正超\",\n  \"email\": \"anzhengchao@gmail.com\",\n  \"avatar\": \"https://avatars.githubusercontent.com/u/1472352?v=3\",\n  \"raw\": {\n    \"login\": \"overtrue\",\n    \"id\": 1472352,\n    \"avatar_url\": \"https://avatars.githubusercontent.com/u/1472352?v=3\",\n    \"gravatar_id\": \"\",\n    \"url\": \"https://api.github.com/users/overtrue\",\n    \"html_url\": \"https://github.com/overtrue\",\n    ...\n  },\n  \"token_response\": {\n    \"access_token\": \"5b1dc56d64fffbd052359f032716cc4e0a1cb9a0\",\n    \"token_type\": \"bearer\",\n    \"scope\": \"user:email\"\n  }\n}\n```\n\n你可以像这样以数组键的形式获取 user 属性：\n\n```php\n$user['id'];        // 1472352\n$user['nickname'];  // \"overtrue\"\n$user['name'];      // \"安正超\"\n$user['email'];     // \"anzhengchao@gmail.com\"\n...\n```\n\n或者使用该 `User` 对象的方法：\n\n```php\nmixed   $user-\u003egetId();\n?string $user-\u003egetNickname();\n?string $user-\u003egetName();\n?string $user-\u003egetEmail();\n?string $user-\u003egetAvatar();\n?string $user-\u003egetRaw();\n?string $user-\u003egetAccessToken();\n?string $user-\u003egetRefreshToken();\n?int    $user-\u003egetExpiresIn();\n?array  $user-\u003egetTokenResponse();\n\n\n```\n\n### 从 OAuth API 响应中取得原始数据\n\n`$user-\u003egetRaw()` 方法会返回一个 **array**。\n\n### 当你使用 userFromCode() 想要获取 token 响应的原始数据\n\n`$user-\u003egetTokenResponse()` 方法会返回一个 **array** 里面是响应从获取 token 时候 API 返回的响应。\n\n\u003e 注意：当你使用 `userFromCode()` 时，这个方法只返回一个 **有效的数组**，否则将返回 **null**，因为 `userFromToken()` 没有 token 的 HTTP 响应。\n\n### 通过 access token 获取用户信息\n\n```php\n$accessToken = 'xxxxxxxxxxx';\n$user = $socialite-\u003euserFromToken($accessToken);\n```\n\n## Enjoy it! :heart:\n\n## 参照\n\n- [Alipay - 用户信息授权](https://opendocs.alipay.com/open/289/105656)\n- [DingTalk - 扫码登录第三方网站](https://ding-doc.dingtalk.com/doc#/serverapi3/mrugr3)\n- [Google - OpenID Connect](https://developers.google.com/identity/protocols/OpenIDConnect)\n- [Github - Authorizing OAuth Apps](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/)\n- [Facebook - Graph API](https://developers.facebook.com/docs/graph-api)\n- [Linkedin - Authenticating with OAuth 2.0](https://developer.linkedin.com/docs/oauth2)\n- [微博 - OAuth 2.0 授权机制说明](http://open.weibo.com/wiki/%E6%8E%88%E6%9D%83%E6%9C%BA%E5%88%B6%E8%AF%B4%E6%98%8E)\n- [QQ - OAuth 2.0 登录 QQ](http://wiki.connect.qq.com/oauth2-0%E7%AE%80%E4%BB%8B)\n- [腾讯云 - OAuth2.0](https://cloud.tencent.com/document/product/306/37730#.E6.8E.A5.E5.85.A5.E8.85.BE.E8.AE.AF.E4.BA.91-oauth)\n- [微信公众平台 - OAuth 文档](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html)\n- [微信开放平台 - 网站应用微信登录开发指南](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list\u0026t=resource/res_list\u0026verify=1\u0026id=open1419316505\u0026token=\u0026lang=zh_CN)\n- [微信开放平台 - 代公众号发起网页授权](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list\u0026t=resource/res_list\u0026verify=1\u0026id=open1419318590\u0026token=\u0026lang=zh_CN)\n- [企业微信 - OAuth 文档](https://open.work.weixin.qq.com/api/doc/90000/90135/91020)\n- [企业微信第三方应用 - OAuth 文档](https://open.work.weixin.qq.com/api/doc/90001/90143/91118)\n- [豆瓣 - OAuth 2.0 授权机制说明](http://developers.douban.com/wiki/?title=oauth2)\n- [抖音 - 网站应用开发指南](http://open.douyin.com/platform/doc)\n- [飞书 - 授权说明](https://open.feishu.cn/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM)\n- [Lark - 授权说明](https://open.larksuite.com/document/ukTMukTMukTM/uMTNz4yM1MjLzUzM)\n- [Tapd - 用户授权说明](https://www.tapd.cn/help/show#1120003271001000093)\n- [Line - OAuth 2.0](https://developers.line.biz/en/docs/line-login/integrate-line-login/)\n- [Gitee - OAuth文档](https://gitee.com/api/v5/oauth_doc#/)\n- [PayPal - OAuth文档](https://developer.paypal.com/docs/log-in-with-paypal/)\n\n## PHP 扩展包开发\n\n\u003e 想知道如何从零开始构建 PHP 扩展包？\n\u003e\n\u003e 请关注我的实战课程，我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Fsocialite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovertrue%2Fsocialite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Fsocialite/lists"}