koalati/oauth2-webflow
Composer 安装命令:
composer require koalati/oauth2-webflow
包简介
A Webflow Provider for OAuth2 client library league/oauth2-client
README 文档
README
This package provides Webflow OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
Requirements
This package requires PHP 8.0 or above.
Installation
To install, use composer:
composer require koalati/oauth2-webflow
Usage
Authorization Code Flow
<?php use Koalati\OAuth2\Client\Provider\Webflow; session_start(); $provider = new Webflow([ // @TODO Fill these based on your app's configuration /** * @see https://developers.webflow.com/docs/getting-started-with-apps#step-2-get-your-client-id-and-secret) * @see https://developers.webflow.com/docs/oauth#user-authorization */ 'clientId' => '{webflow-app-id}', 'clientSecret' => '{webflow-app-secret}', 'redirectUri' => 'https://example.com/callback-url', ]); // If we don't have an authorization code then get one if (!isset($_GET['code'])) { $authUrl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->getState(); echo "<a href='{$authUrl}'>Log in with Webflow</a>"; exit; } // Check given state against previously stored one to mitigate CSRF attack if (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); http_response_code(403); echo 'Invalid state / CSRF token.'; exit; } // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // At this point, you have an access token you can use to interact with the API. // You can use it to look up the user's information, or to make any other API calls. try { // We got an access token, let's now get the user's details $user = $provider->getResourceOwner($token); // Use these details to create a new profile printf('<h1>Hello %s!</h1>', $user->getFirstName()); echo "<strong>Your Webflow user info:</strong><br>"; echo '<pre>'; print_r($user); echo '</pre>'; } catch (\Exception $e) { // Failed to get user details exit("An error has occured while fetching the Webflow user's information."); } echo "<strong>Your Webflow access token:</strong> (keep this safe!)<br>"; echo '<pre>'; // Use this to interact with an API on the users behalf echo $token->getToken(); echo '</pre>';
Revoke Code Flow
<?php use Koalati\OAuth2\Client\Provider\Webflow; $provider = new Webflow([ // @TODO Fill these based on your app's configuration /** * @see https://developers.webflow.com/docs/getting-started-with-apps#step-2-get-your-client-id-and-secret) * @see https://developers.webflow.com/docs/oauth#user-authorization */ 'clientId' => '{webflow-app-id}', 'clientSecret' => '{webflow-app-secret}', 'redirectUri' => 'https://example.com/callback-url', ]); // Use the token of "Authorization Code Flow" which you saved somewhere for the user $token = $token->getToken(); try { $provider->revokeAccessToken($token); } catch (Exception $e) { exit('Failed to revoke the Webflow access token.'); }
Webflow API client
This package does not provide any API interactions other than OAuth 2.0 authentication.
However, if you need to interact with the Webflow API, we recommend you check
out the koalati/webflow-api-client
package.
Contributing
Please see CONTRIBUTING for details.
Credits
The core of this package was developed by Koalati, a QA platform for web developers and agencies.
Check out other contributors who helped maintain and make this package better: All Contributors.
License
The MIT License (MIT). Please see License File for more information.
koalati/oauth2-webflow 适用场景与选型建议
koalati/oauth2-webflow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 134 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 koalati/oauth2-webflow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koalati/oauth2-webflow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 134
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-17