Skip to content

Commit

Permalink
add grant message to login page
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Nikolaev <kinolaev@gmail.com>
  • Loading branch information
kinolaev committed Sep 14, 2020
1 parent c1ff7de commit e268958
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
23 changes: 22 additions & 1 deletion core/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OC\User\Session;
use OC_App;
use OC_Util;
use OCA\OAuth2\Db\ClientMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand Down Expand Up @@ -83,6 +84,8 @@ class LoginController extends Controller {
private $initialStateService;
/** @var WebAuthnManager */
private $webAuthnManager;
/** @var ClientMapper */
private $clientMapper;

public function __construct(?string $appName,
IRequest $request,
Expand All @@ -96,7 +99,8 @@ public function __construct(?string $appName,
Throttler $throttler,
Chain $loginChain,
IInitialStateService $initialStateService,
WebAuthnManager $webAuthnManager) {
WebAuthnManager $webAuthnManager,
ClientMapper $clientMapper) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->config = $config;
Expand All @@ -109,6 +113,7 @@ public function __construct(?string $appName,
$this->loginChain = $loginChain;
$this->initialStateService = $initialStateService;
$this->webAuthnManager = $webAuthnManager;
$this->clientMapper = $clientMapper;
}

/**
Expand Down Expand Up @@ -176,6 +181,22 @@ public function showLoginForm(string $user = null, string $redirect_url = null):

if (!empty($redirect_url)) {
$this->initialStateService->provideInitialState('core', 'loginRedirectUrl', $redirect_url);

$grant_url = $this->urlGenerator->linkToRoute('core.ClientFlowLogin.grantPage');
if (strpos($redirect_url, $grant_url) === 0) {
parse_str(parse_url($redirect_url, PHP_URL_QUERY), $grant_query);
if (empty($grant_query['clientIdentifier'])) {
$userAgent = $this->request->getHeader('USER_AGENT');
$clientName = $userAgent !== '' ? $userAgent : 'unknown';
} else {
$client = $this->clientMapper->getByIdentifier($grant_query['clientIdentifier']);
$clientName = $client->getName();
}
$this->initialStateService->provideInitialState('core', 'loginGrantParams', [
'client' => Util::sanitizeHTML($clientName),
'instanceName' => Util::sanitizeHTML($this->defaults->getName())
]);
}
}

$this->initialStateService->provideInitialState(
Expand Down
Loading

0 comments on commit e268958

Please sign in to comment.