Skip to content

Commit

Permalink
Merge pull request #1 from aleron75/master
Browse files Browse the repository at this point in the history
Add README
  • Loading branch information
giacmir authored Mar 13, 2020
2 parents e18ffd2 + ea58803 commit 2b870c5
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
48 changes: 26 additions & 22 deletions Plugin/AuthenticateWithGoogle.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,32 @@ public function __construct(
*/
public function beforeExecute(Login $subject): void
{
if ($this->isEnabled->execute()) {
$authCode = $this->request->getParam('code', '');
if (!empty($authCode)) {
try {
$googleUserInfo = $this->getGoogleUserInfo->execute($authCode);
$this->createUserFromGoogleUserInfo->execute($googleUserInfo);

$this->authenticateByEmail->execute($googleUserInfo->getEmail());

$this->eventManager->dispatch(
'backend_auth_user_login_success',
['user' => $this->authSession]
);
} catch (Exception $e) {
$this->eventManager->dispatch(
'backend_auth_user_login_failed',
['user_name' => '', 'exception' => $e]
);

$this->messageManager->addErrorMessage($e->getMessage());
}
}
if (!$this->isEnabled->execute()) {
return;
}

$authCode = $this->request->getParam('code', '');
if (empty($authCode)) {
return;
}

try {
$googleUserInfo = $this->getGoogleUserInfo->execute($authCode);
$this->createUserFromGoogleUserInfo->execute($googleUserInfo);

$this->authenticateByEmail->execute($googleUserInfo->getEmail());

$this->eventManager->dispatch(
'backend_auth_user_login_success',
['user' => $this->authSession]
);
} catch (Exception $e) {
$this->eventManager->dispatch(
'backend_auth_user_login_failed',
['user_name' => '', 'exception' => $e]
);

$this->messageManager->addErrorMessage($e->getMessage());
}
}
}
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Backend Google Sign On for Magento 2
This is a Magento 2 extension that allows to authenticate into Magento 2 Admin Panel using Google Sign On services.

## Installation
Install the extension through composer:

composer require msp/module-backend-google-sign-on

Once Composer finishes installing the dependencies, run:

bin/magento setup:upgrade

## Configuration
After the module is installed, authenticate into Admin Panel and go to `STORES > Settings > Configuration > SECURITY > Google Backend Sign On`.

You should see the following configuation fields:

![Configuration](doc/img/configuration-01.png)

To fill the **Client ID** ad **Client Secret** fields, go to https://console.developers.google.com/ to create the required **OAuth client ID** credentials (read detailed instructions [here](https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow?hl=it)).

As **Authorized JavaScript origins** set the base URL of the site where you are installing the extension.

As **Authorized redirect URLs** set the URL of the Admin Panel.

You can also define a set of domain-based rules to automatically assign a role to a user or to force a user to use the Google Sign On, as shown below:

![Rules](doc/img/rules-01.png)

## Usage
Once enabled and configured, the extension adds a **Google Login** button in the sign in form of the Admin Panel, as shown below:

![Login](doc/img/login-01.png)

## Contributing
Contributions are very welcome. In order to contribute, please fork this repository and [submit a pull request](https://help.github.com/articles/creating-a-pull-request/).

## License
Copyright © MageSpecialist - Skeeller srl. All rights reserved.
Binary file added doc/img/configuration-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/login-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/rules-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b870c5

Please sign in to comment.