Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/webchemistry/oauth-social

LinkedIn, Google oauth
https://github.com/webchemistry/oauth-social

Last synced: about 1 month ago
JSON representation

LinkedIn, Google oauth

Awesome Lists containing this project

README

        

## Usage

Nette extension:
```neon
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
```php
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:');
}

}

}
```