createlinux / oauth
v3.0.13
2024-07-21 02:17 UTC
Requires
- php: >=8.0
- dev-main
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-12-21 03:12:59 UTC
README
oauth2.0 client package
在.env里配置以下参数
#客户端id
LITCHI_AUTH_CLIENT_ID=
#客户端秘钥
LITCHI_AUTH_CLIENT_SECRET=
#应用回调地址
LITCHI_AUTH_CLIENT_REDIRECT_URI=
#认证服务器服务器端url,开发时填写,正式环境可省略
LITCHI_AUTH_CENTER_SERVER_URI=
#认证服务器客户端端url,开发时填写,正式环境可省略
LITCHI_AUTH_CENTER_CLIENT_URI=
客户端代码示例,如果存在cookie内使用以下代码,如果存在localStorage则需要修改响应体
public function store(Request $request) { $code = $request->post('code'); $oauthClient = create_litchi_oauth_client(); if (!$code) { //build redirect url return Http::created("ok", [ 'redirect_uri' => $oauthClient->generateAuthCodeURI() ]); } $response = $oauthClient->createNewAuthToken($code); if (!$response->isSuccess()) { return Http::badRequest($response->getMessage()); } return Http::created(context: [ 'access_token' => Crypt::encrypt($response->getAccessToken()) ])->withCookie( cookie( 'access_token', Crypt::encrypt($response->getAccessToken()), $response->getExpirationSeconds() / 60 ) ); }
清除token示例,如果存在cookie内使用以下代码,如果存在localStorage则需要修改响应体
public function destroy(Request $request, $me) { $accessToken = Cookie::get('access_token'); $cookie = cookie( 'access_token', null, -1 ); if (!$accessToken) { return Http::deleted('退出登录成功')->withCookie($cookie); } $oauthClient = create_litchi_oauth_client(); $response = $oauthClient->removeAccessToken(Crypt::decrypt($accessToken)); if (!$response->isSuccess()) { return Http::badRequest($response->getMessage()); } return Http::deleted('退出登录成功')->withCookie($cookie); }