codeinc / google-oauth2-middleware
此包已被弃用且不再维护。未建议替代包。
一个使用JSON Web Tokens管理Google OAuth2身份验证的PSR-15中间件
1.3.1
2018-10-08 14:21 UTC
Requires
- php: >=7.1
- codeinc/psr7-responses: ^2
- codeinc/url: ^1.4
- firebase/php-jwt: ^5.0
- google/apiclient: ^2.0
- hansott/psr7-cookies: ^1.0
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
This package is auto-updated.
Last update: 2020-02-08 17:41:28 UTC
README
GoogleOAuth2Middleware
是一个用PHP 7编写的PSR-15中间件,旨在使用JSON Web Tokens或PHP会话管理Google OAuth2身份验证。与Google的交互使用Google API PHP客户端。JSON Web Tokens由Firebase JWT实现生成和读取。
身份验证信息(AuthToken
对象)使用存储驱动类(实现AuthTokenStorageDriverInterface
)存储,可以是使用JwtStorageDriver
的JSON Web Tokenscookie,也可以使用SessionStorageDriver
的PHP会话($_SESSION
数组)。
一旦用户经过身份验证,无论是从Google接收授权码还是使用授权cookie,用户信息都会在PSR-7请求的auth属性中提供(默认)。
您可以通过发送实现LogoutResponseInterface
的PSR-7响应来断开当前用户。
使用方法
<?php use CodeInc\GoogleOAuth2Middleware\GoogleOAuth2Middleware; use CodeInc\GoogleOAuth2Middleware\AuthTokenStorage\JwtStorageDriver; $googleOAuth2Middleware = new GoogleOAuth2Middleware( // a fully configured Google client (the client redirect URI must be set) new Google_Client(), // storing the auth token using a JWT cookie new JwtStorageDriver("a_very_secret_key"), // the lifespan of the authentication (optionnal, 30 minutres by default) DateInterval::createFromDateString("1 hour") ); // You can (optionnally) specify a request handler which will be called for unauthenticated requests. // If not request handler is set the middleware will generate a PSR-7 redirect response toward the // Google Oauth 2 page $googleOAuth2Middleware->setUnauthenticatedRequestHandler(new A_PSR7_Request_Handler());
安装
此库可通过Packagist获取,并可以使用Composer进行安装。
composer require codeinc/google-oauth2-middleware
许可证
此库在MIT许可证下发布(请参阅LICENSE
文件)。