-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: e-five <[email protected]>
- Loading branch information
Showing
14 changed files
with
412 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240503224350 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'Add SimpleLogin SSO'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE "user" ADD oauth_simple_login_id VARCHAR(255) DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE "user" DROP oauth_simple_login_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Security; | ||
|
||
use App\Controller\AbstractController; | ||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class SimpleLoginController extends AbstractController | ||
{ | ||
public function connect(ClientRegistry $clientRegistry): Response | ||
{ | ||
return $clientRegistry | ||
->getClient('simplelogin') | ||
->redirect([ | ||
'openid', | ||
'email', | ||
'profile', | ||
]); | ||
} | ||
|
||
public function verify(Request $request, ClientRegistry $client) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Provider; | ||
|
||
use League\OAuth2\Client\Provider\AbstractProvider; | ||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; | ||
use League\OAuth2\Client\Token\AccessToken; | ||
use League\OAuth2\Client\Tool\BearerAuthorizationTrait; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class SimpleLogin extends AbstractProvider | ||
{ | ||
use BearerAuthorizationTrait; | ||
|
||
protected $baseUrl = 'https://app.simplelogin.io/'; | ||
|
||
public function __construct(array $options = [], array $collaborators = []) | ||
{ | ||
parent::__construct($options, $collaborators); | ||
} | ||
|
||
protected function getBaseUrl() | ||
{ | ||
return rtrim($this->baseUrl, '/').'/'; | ||
} | ||
|
||
protected function getAuthorizationHeaders($token = null) | ||
{ | ||
return ['Authorization' => 'Bearer '.$token]; | ||
} | ||
|
||
public function getBaseAuthorizationUrl() | ||
{ | ||
return $this->getBaseUrl().'oauth2/authorize'; | ||
} | ||
|
||
public function getBaseAccessTokenUrl(array $params) | ||
{ | ||
return $this->getBaseUrl().'oauth2/token'; | ||
} | ||
|
||
public function getResourceOwnerDetailsUrl(AccessToken $token) | ||
{ | ||
return $this->getBaseUrl().'oauth2/userinfo'; | ||
} | ||
|
||
protected function getDefaultScopes() | ||
{ | ||
return ['openid', 'profile', 'email']; | ||
} | ||
|
||
protected function checkResponse(ResponseInterface $response, $data) | ||
{ | ||
if (!empty($data['error'])) { | ||
$error = htmlentities($data['error'], ENT_QUOTES, 'UTF-8'); | ||
$message = htmlentities($data['error_description'], ENT_QUOTES, 'UTF-8'); | ||
throw new IdentityProviderException($message, $response->getStatusCode(), $response); | ||
} | ||
} | ||
|
||
protected function createResourceOwner(array $response, AccessToken $token) | ||
{ | ||
return new SimpleLoginResourceOwner($response); | ||
} | ||
|
||
protected function getScopeSeparator() | ||
{ | ||
return ' '; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Provider; | ||
|
||
use League\OAuth2\Client\Provider\ResourceOwnerInterface; | ||
|
||
class SimpleLoginResourceOwner implements ResourceOwnerInterface | ||
{ | ||
protected $response; | ||
|
||
public function __construct(array $response) | ||
{ | ||
$this->response = $response; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->getResponseValue('sub'); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->getResponseValue('name'); | ||
} | ||
|
||
public function getEmail() | ||
{ | ||
return $this->getResponseValue('email'); | ||
} | ||
|
||
public function getPictureUrl() | ||
{ | ||
return $this->getResponseValue('avatar_url'); | ||
} | ||
|
||
public function toArray() | ||
{ | ||
return $this->response; | ||
} | ||
|
||
protected function getResponseValue($key) | ||
{ | ||
$keys = explode('.', $key); | ||
$value = $this->response; | ||
|
||
foreach ($keys as $k) { | ||
if (isset($value[$k])) { | ||
$value = $value[$k]; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
return $value; | ||
} | ||
} |
Oops, something went wrong.