Skip to content

Commit

Permalink
Merge pull request #83 from arodu/feature/openid-connect-linkedin
Browse files Browse the repository at this point in the history
Feature/openid connect linkedin
  • Loading branch information
steinkel authored Sep 30, 2023
2 parents 4e99411 + ad6e98b commit 7d73629
Show file tree
Hide file tree
Showing 3 changed files with 403 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Social/Service/OpenIDConnectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getIdTokenKeys(): array
$this->getConfig('openid.baseUrl')
);
}
$client = new Client();
$client = $this->getHttpClient();
$jwksData = $client->get($jwksUri)->getJson();
if (!$jwksData) {
throw new BadRequestException(
Expand All @@ -77,8 +77,13 @@ protected function getIdTokenKeys(): array
public function discover(): array
{
$openidUrl = $this->getConfig('openid.url');
$client = new Client();
$client = $this->getHttpClient();

return $client->get($openidUrl)->getJson();
}

protected function getHttpClient(): Client
{
return new Client();
}
}
81 changes: 81 additions & 0 deletions tests/TestCase/Social/Mapper/LinkedInOpenIDConnectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\LinkedIn;
use CakeDC\Auth\Social\Mapper\LinkedInOpenIDConnect;

class LinkedInOpenIDConnectTest 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 = [
'sub' => '1',
'token' => $token,
'email' => '[email protected]',
'given_name' => 'Test',
'family_name' => 'User',
'industry' => 'Computer Software',
'location' => [
'country' => [
'code' => 'es',
],
'name' => 'Spain',
],
'picture' => 'https://media.licdn.com/mpr/mprx/test.jpg',


'bio' => 'The best test user in the world.',
'publicProfileUrl' => 'https://www.linkedin.com/in/test',
];
$providerMapper = new LinkedInOpenIDConnect();
$user = $providerMapper($rawData);

$this->assertEquals([
'id' => '1',
'username' => null,
'full_name' => null,
'first_name' => 'Test',
'last_name' => 'User',
'email' => '[email protected]',
'avatar' => 'https://media.licdn.com/mpr/mprx/test.jpg',
'gender' => null,
'link' => 'https://www.linkedin.com',
'bio' => 'The best test user in the world.',
'locale' => null,
'validated' => true,
'credentials' => [
'token' => 'test-token',
'secret' => null,
'expires' => 1490988496,
],
'raw' => $rawData,
], $user);
}
}
Loading

0 comments on commit 7d73629

Please sign in to comment.