PHP code example of webchemistry / oauth-social
1. Go to this page and download the library: Download webchemistry/oauth-social 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/ */
webchemistry / oauth-social example snippets
class Presenter
{
/** @var GoogleOAuthAccessor @inject */
public GoogleOAuthAccessor $googleOAuthAccessor;
public function actionLogin(?string $backlink): void
{
$this->redirectUrl($this->googleOAuthAccessor->get('login')->getAuthorizationUrl([
'backlink' => $backlink,
]));
}
public function actionRedirection(): void
{
try {
$identity = $this->googleOAuthAccessor->get('login')->getIdentityAndVerify();
} catch (OAuthSocialException $exception) {
$this->flashMessage($exception->getMessage(), 'error');
$this->redirect('Homepage:');
} catch (Throwable $exception) {
$this->flashMessage('Something gone wrong.', 'error');
$this->redirect('Homepage:');
}
}
}