Compare commits
No commits in common. "4dc08dffc918cf5831b1b32c333be2e046413db4" and "c9a06e5ada94be78cc5971cfec6165f0d182ab8e" have entirely different histories.
4dc08dffc9
...
c9a06e5ada
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE `oauth_tokens`
|
|
||||||
DROP `audience`;
|
|
@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE `oauth_clients`
|
|
||||||
MODIFY `client_id` varchar(255) CHARACTER SET ascii COLLATE ascii_bin NOT NULL;
|
|
@ -14,13 +14,12 @@ class AddOAuthClientCommand extends Command
|
|||||||
{
|
{
|
||||||
$this->setName('oauth:add-client')
|
$this->setName('oauth:add-client')
|
||||||
->setDescription('Adding of OAuth client.')
|
->setDescription('Adding of OAuth client.')
|
||||||
->addArgument('client-id', InputArgument::OPTIONAL, 'Client ID')
|
|
||||||
->addArgument('preapproved', InputArgument::OPTIONAL, 'Preapproved');
|
->addArgument('preapproved', InputArgument::OPTIONAL, 'Preapproved');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(InputInterface $input, OutputInterface $output): int
|
public function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
$clientId = $input->getArgument('client-id') ? $input->getArgument('client-id') : bin2hex(random_bytes(8));
|
$clientId = bin2hex(random_bytes(8));
|
||||||
$clientSecret = bin2hex(random_bytes(20));
|
$clientSecret = bin2hex(random_bytes(20));
|
||||||
|
|
||||||
$oAuthClient = new OAuthClient();
|
$oAuthClient = new OAuthClient();
|
||||||
@ -28,7 +27,7 @@ class AddOAuthClientCommand extends Command
|
|||||||
$oAuthClient->setClientSecret($clientSecret);
|
$oAuthClient->setClientSecret($clientSecret);
|
||||||
$oAuthClient->setCreatedDate(new DateTime());
|
$oAuthClient->setCreatedDate(new DateTime());
|
||||||
|
|
||||||
if ($input->getArgument('preapproved')) {
|
if ($input->hasArgument('preapproved') && $input->getArgument('preapproved')) {
|
||||||
$oAuthClient->setPreapproved($input->getArgument('preapproved'));
|
$oAuthClient->setPreapproved($input->getArgument('preapproved'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ class OAuthAuthController implements ISecured
|
|||||||
}
|
}
|
||||||
|
|
||||||
$redirectUriParsed = parse_url($redirectUri);
|
$redirectUriParsed = parse_url($redirectUri);
|
||||||
$redirectUriBase = $redirectUriParsed['scheme'] . '://' . $redirectUriParsed['host'] . $redirectUriParsed['path'];
|
$redirectUriHost = $redirectUriParsed['scheme'] . '://' . $redirectUriParsed['host'];
|
||||||
|
$redirectUriBase = $redirectUriHost . $redirectUriParsed['path'];
|
||||||
$redirectUriQuery = [];
|
$redirectUriQuery = [];
|
||||||
if (isset($redirectUriParsed['query'])) {
|
if (isset($redirectUriParsed['query'])) {
|
||||||
parse_str($redirectUriParsed['query'], $redirectUriQuery);
|
parse_str($redirectUriParsed['query'], $redirectUriQuery);
|
||||||
@ -72,6 +73,7 @@ class OAuthAuthController implements ISecured
|
|||||||
$token->setUser($user);
|
$token->setUser($user);
|
||||||
$token->setCode($code);
|
$token->setCode($code);
|
||||||
$token->setAccessToken($accessToken);
|
$token->setAccessToken($accessToken);
|
||||||
|
$token->setAudience($redirectUriHost);
|
||||||
$token->setCreatedDate(new DateTime());
|
$token->setCreatedDate(new DateTime());
|
||||||
$token->setExpiresDate(new DateTime('+5 minutes'));
|
$token->setExpiresDate(new DateTime('+5 minutes'));
|
||||||
$this->pdm->saveToDb($token);
|
$this->pdm->saveToDb($token);
|
||||||
|
@ -59,7 +59,7 @@ class OAuthController
|
|||||||
'iat' => (int)$token->getCreatedDate()->getTimestamp(),
|
'iat' => (int)$token->getCreatedDate()->getTimestamp(),
|
||||||
'nbf' => (int)$token->getCreatedDate()->getTimestamp(),
|
'nbf' => (int)$token->getCreatedDate()->getTimestamp(),
|
||||||
'exp' => (int)$token->getExpiresDate()->getTimestamp(),
|
'exp' => (int)$token->getExpiresDate()->getTimestamp(),
|
||||||
'aud' => $clientId,
|
'aud' => $token->getAudience(),
|
||||||
'nonce' => $token->getNonce()
|
'nonce' => $token->getNonce()
|
||||||
], $this->getUserInfoInternal(
|
], $this->getUserInfoInternal(
|
||||||
$this->userRepository->getById($token->getUserId()),
|
$this->userRepository->getById($token->getUserId()),
|
||||||
|
@ -7,7 +7,7 @@ class OAuthToken extends Model
|
|||||||
{
|
{
|
||||||
protected static string $table = 'oauth_tokens';
|
protected static string $table = 'oauth_tokens';
|
||||||
|
|
||||||
protected static array $fields = ['scope', 'nonce', 'user_id', 'code', 'access_token', 'created', 'expires'];
|
protected static array $fields = ['scope', 'nonce', 'user_id', 'code', 'access_token', 'audience', 'created', 'expires'];
|
||||||
|
|
||||||
protected static array $relations = ['user' => User::class];
|
protected static array $relations = ['user' => User::class];
|
||||||
|
|
||||||
@ -25,6 +25,8 @@ class OAuthToken extends Model
|
|||||||
|
|
||||||
private string $accessToken = '';
|
private string $accessToken = '';
|
||||||
|
|
||||||
|
private string $audience = '';
|
||||||
|
|
||||||
private DateTime $created;
|
private DateTime $created;
|
||||||
|
|
||||||
private DateTime $expires;
|
private DateTime $expires;
|
||||||
@ -64,6 +66,11 @@ class OAuthToken extends Model
|
|||||||
$this->accessToken = $accessToken;
|
$this->accessToken = $accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAudience(string $audience): void
|
||||||
|
{
|
||||||
|
$this->audience = $audience;
|
||||||
|
}
|
||||||
|
|
||||||
public function setCreatedDate(DateTime $created): void
|
public function setCreatedDate(DateTime $created): void
|
||||||
{
|
{
|
||||||
$this->created = $created;
|
$this->created = $created;
|
||||||
@ -119,6 +126,11 @@ class OAuthToken extends Model
|
|||||||
return $this->accessToken;
|
return $this->accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAudience(): string
|
||||||
|
{
|
||||||
|
return $this->audience;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCreatedDate(): DateTime
|
public function getCreatedDate(): DateTime
|
||||||
{
|
{
|
||||||
return $this->created;
|
return $this->created;
|
||||||
|
Loading…
Reference in New Issue
Block a user