webchemistry/oauth-social

There is no license information available for the latest version (v1.3.3) of this package.

v1.3.3 2022-08-11 10:13 UTC

This package is auto-updated.

Last update: 2024-11-25 23:14:31 UTC


README

Nette extension:

extensions:
	oAuthSocial: WebChemistry\OAuthSocial\DI\OAuthSocialExtension

oAuthSocial:
	google:
		id: 'clientId'
		secret: 'clientSecret'
		instances:
			login: 'Module:Presenter:redirection'
	linkedIn:
		id: 'clientId'
		secret: 'clientSecret'
		instances:
			login: 'Module:Presenter:redirection'

Presenter

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:');
		}

	}

}