Skip to content

Commit

Permalink
[skip ci] Fix typos in oauth doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Jun 8, 2020
1 parent 2dcb4ba commit 0c2d0d4
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions docs/extra/oauth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In the root of your project:
composer require phpmv/ubiquity-oauth
.. note:: It is also possible to add the **ubiquity-oauth** dependency using the Compose part of the administration module.
.. note:: It is also possible to add the **ubiquity-oauth** dependency using the **Composer** part of the administration module.

.. image:: /_static/images/composer/composer-add-1.png
:class: bordered
Expand Down Expand Up @@ -47,7 +47,7 @@ Click on the **Create Oauth controller** button and assign to the route the valu

Validate and reset the router cache:

.. image:: /_static/images/oauth/create-oauth-controller-create.png
.. image:: /_static/images/oauth/create-oauth-controller-created.png
:class: bordered

Providers
Expand All @@ -69,3 +69,61 @@ Post Login Information:

.. image:: /_static/images/oauth/google-check-infos.png
:class: bordered

OAuthController customization
-----------------------------
The controller created is the following:

.. code-block:: php
:caption: app/controllers/OAuthTest.php
namespace controllers;
use Hybridauth\Adapter\AdapterInterface;
/**
* Controller OAuthTest
*/
class OAuthTest extends \Ubiquity\controllers\auth\AbstractOAuthController{
public function index(){
}
/**
* @get("oauth/{name}")
*/
public function _oauth(string $name):void {
parent::_oauth($name);
}
protected function onConnect(string $name,AdapterInterface $provider){
//TODO
}
}
- The **_oauth** method corresponds to the callback url
- The **onConnect** method is triggered on connection and can be overridden.


Example :

- Possible retrieval of an associated user in the database
- or creation of a new user
- Adding the logged-in user and redirection

.. code-block:: php
:caption: app/controllers/OAuthTest.php
protected function onConnect(string $name, AdapterInterface $provider) {
$userProfile = $provider->getUserProfile();
$key = md5($name . $userProfile->identifier);
$user = DAO::getOne(User::class, 'oauth= ?', false, [
$key
]);
if (! isset($user)) {
$user = new User();
$user->setOauth($key);
$user->setLogin($userProfile->displayName);
DAO::save($user);
}
USession::set('activeUser', $user);
header('location:/');
}

0 comments on commit 0c2d0d4

Please sign in to comment.