carry0987 / falcon
Falcon - 一种灵活的PHP框架,专为无缝集成第三方社交登录而设计。支持包括谷歌、Facebook、Twitter等主要服务,通过统一的界面和设计模式提供简单安全的认证。
1.0.4
2024-01-14 12:26 UTC
Requires
- php: >=7.4
- google/auth: ^1.33
- guzzlehttp/guzzle: ^7.8
README
Falcon是一种灵活的PHP框架,专为无缝集成第三方社交平台登录机制而设计。
它通过统一的界面和设计模式提供简单安全的用户认证,易于实现和维护。
目前,它支持以下主要服务
- GitHub
- 谷歌
- Discord
- Line
- Telegram
无论您是在开发新应用还是增强现有系统,Falcon都可以帮助您快速实现社交登录功能,同时确保用户数据的安全和隐私。
功能
- 统一界面:使用标准方法操作所有支持的社会服务。
- 易于集成:通过直观的配置和清晰的文档快速集成到您的项目中。
- 安全性:实现最佳当前安全实践,以保护登录过程和数据。
- 灵活设计:轻松添加或删除特定社交服务,而不会影响现有系统架构。
- 开源支持:从开源社区的不懈改进和支持中受益。
安装
使用Composer将Falcon安装到您的项目中Composer
composer require carry0987/falcon
使用示例
首先,在项目中为每个第三方服务设置凭证和其他配置信息
$config = [ 'providers' => [ 'github' => [ 'client_id' => 'your_github_client_id', 'client_secret' => 'your_github_client_secret', 'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=github' ], 'line' => [ 'client_id' => 'your_line_client_id', // Channel ID 'client_secret' => 'your_line_client_secret', // Channel secret 'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=line' ], 'telegram' => [ 'client_id' => 'your_telegram_client_id', // Bot username 'client_secret' => 'your_telegram_client_secret', // Bot token 'redirect_uri' => 'https://your-website.com/path/to/callback.php?provider=telegram' ], // Configuration for other third-party login providers... ], ];
接下来,创建一个Falcon
实例,并使用所选第三方提供者启动登录过程
$falcon = new \carry0987\Falcon\Falcon($config); $providerName = $_GET['provider'] ?? 'default'; $provider = $falcon->createProvider($providerName); // Start the OAuth login process if (!isset($_GET['code'])) { $loginUrl = $provider->authorize(); // Redirect user to the login page header('Location: ' . $loginUrl); exit; } // Handle the callback and retrieve user information if ($providerName === 'telegram') { // Special handling for Telegram login flow... } else { $accessToken = $provider->getTokenWithAuthCode($_GET['code']); $user = $provider->getUser(); // Output user information echo "<pre>" . print_r($user, true) . "</pre>"; }
要结束登录
会话,您可以吊销访问令牌
if (isset($_GET['logout'])) { $provider->revokeAccessToken($_GET['access_token'] ?? null); // Redirect back to the login page or homepage header('Location: ?provider=' . $providerName); exit; }
您可以在代码中添加更多标准OAuth处理逻辑,例如处理错误状态、重定向到其他页面等。
支持
如果您有任何问题,请在我们的GitHub存储库中提交问题。
在项目中享受使用Falcon吧!