PHP code example of createlinux / oauth
1. Go to this page and download the library: Download createlinux/oauth library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
createlinux / oauth example snippets
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
)
);
}
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);
}