Skip to content

Commit

Permalink
Merge pull request #73 from arodu/feature/microsoft-login
Browse files Browse the repository at this point in the history
Feature/microsoft login
  • Loading branch information
rochamarcelo authored Dec 5, 2022
2 parents 716617e + 3af4f50 commit 9e126f8
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@
"psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json",
"coverage-test": "phpunit --stderr --coverage-clover=clover.xml"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
10 changes: 10 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/amazon',
]
],
'azure' => [
'service' => 'CakeDC\Auth\Social\Service\OAuth2Service',
'className' => 'TheNetworg\OAuth2\Client\Provider\Azure',
'mapper' => 'CakeDC\Auth\Social\Mapper\Azure',
'options' => [
'redirectUri' => Router::fullBaseUrl() . '/auth/azure',
'linkSocialUri' => Router::fullBaseUrl() . '/link-social/azure',
'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/azure',
]
],
],
'OneTimePasswordAuthenticator' => [
'checker' => \CakeDC\Auth\Authentication\DefaultOneTimePasswordAuthenticationChecker::class,
Expand Down
40 changes: 40 additions & 0 deletions src/Social/Mapper/Azure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace CakeDC\Auth\Social\Mapper;

class Azure extends AbstractMapper
{
/**
* Map for provider fields
*
* @var array
*/
protected $_mapFields = [
'id' => 'sub',
'full_name' => 'name',
'username' => 'unique_name',
'email' => 'upn',
];

/**
* Get link property value
*
* @param mixed $rawData raw data
* @return string
*/
protected function _link($rawData)
{
return '#';
}
}
78 changes: 78 additions & 0 deletions tests/TestCase/Social/Mapper/AzureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);

/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

namespace CakeDC\Auth\Test\TestCase\Social\Mapper;

use Cake\TestSuite\TestCase;
use CakeDC\Auth\Social\Mapper\Azure;

class AzureTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}

public function tearDown(): void
{
parent::tearDown();
}

public function testMap()
{
$token = new \League\OAuth2\Client\Token\AccessToken([
'access_token' => 'test-token',
'expires' => 1490988496,
]);
$rawData = [
'token' => $token,
'aud' => 'ef044865-c304-4707-bce2-2c8cb469f093',
'iss' => 'https://sts.windows.net/b5a44686-40bd-47e2-8e01-e52f214f2c8f/',
'iat' => 1660940688,
'nbf' => 1660940688,
'exp' => 1660944588,
'amr' => [ ],
'ipaddr' => '127.0.0.1',
'name' => 'Test',
'oid' => '8a27cdf6-50c6-455b-af9d-ec60381ee8b9',
'rh' => '0.AQUAhkaktb1A4keOAeUvIU8sj2VIBO8EwwdHvOIsjLRp8JMFAJM.',
'sub' => 'wsAdh5DgzKg_-dz9xap8P0Sqnar2-CKifp0noideBv4',
'tid' => 'b5a44686-40bd-47e2-8e01-e52f214f2c8f',
'unique_name' => '[email protected]',
'upn' => '[email protected]',
'ver' => '1.0',
];
$providerMapper = new Azure();
$user = $providerMapper($rawData);
$this->assertEquals([
'id' => 'wsAdh5DgzKg_-dz9xap8P0Sqnar2-CKifp0noideBv4',
'username' => '[email protected]',
'full_name' => 'Test',
'first_name' => null,
'last_name' => null,
'email' => '[email protected]',
'avatar' => null,
'gender' => null,
'link' => '#',
'bio' => null,
'locale' => null,
'validated' => true,
'credentials' => [
'token' => 'test-token',
'secret' => null,
'expires' => 1490988496,
],
'raw' => $rawData,
], $user);
}
}

0 comments on commit 9e126f8

Please sign in to comment.