Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions core/Controller/ClientFlowLoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function showAuthPickerPage($clientIdentifier = '') {
'instanceName' => $this->defaults->getName(),
'urlGenerator' => $this->urlGenerator,
'stateToken' => $stateToken,
'serverHost' => $this->request->getServerHost(),
'serverHost' => $this->getServerPath(),
'oauthState' => $this->session->get('oauth.state'),
],
'guest'
Expand Down Expand Up @@ -235,7 +235,7 @@ public function grantPage($stateToken = '',
'instanceName' => $this->defaults->getName(),
'urlGenerator' => $this->urlGenerator,
'stateToken' => $stateToken,
'serverHost' => $this->request->getServerHost(),
'serverHost' => $this->getServerPath(),
'oauthState' => $this->session->get('oauth.state'),
],
'guest'
Expand Down Expand Up @@ -345,32 +345,34 @@ public function generateAppPassword($stateToken,
);
$this->session->remove('oauth.state');
} else {
$serverPostfix = '';
$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);

if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
}
// Clear the token from the login here
$this->tokenProvider->invalidateToken($sessionId);
}

$protocol = $this->request->getServerProtocol();
return new Http\RedirectResponse($redirectUri);
}

if ($protocol !== "https") {
$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
$protocol = 'https';
}
}
private function getServerPath(): string {
$serverPostfix = '';

if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
}

$serverPath = $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
$redirectUri = 'nc://login/server:' . $serverPath . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
$protocol = $this->request->getServerProtocol();

// Clear the token from the login here
$this->tokenProvider->invalidateToken($sessionId);
if ($protocol !== "https") {
$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
$protocol = 'https';
}
}

return new Http\RedirectResponse($redirectUri);
return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
}
}
10 changes: 8 additions & 2 deletions tests/Core/Controller/ClientFlowLoginControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public function testShowAuthPickerPageWithOcsHeader() {
->expects($this->once())
->method('getServerHost')
->willReturn('example.com');
$this->request
->method('getServerProtocol')
->willReturn('https');

$expected = new TemplateResponse(
'core',
Expand All @@ -172,7 +175,7 @@ public function testShowAuthPickerPageWithOcsHeader() {
'instanceName' => 'ExampleCloud',
'urlGenerator' => $this->urlGenerator,
'stateToken' => 'StateToken',
'serverHost' => 'example.com',
'serverHost' => 'https://example.com',
'oauthState' => 'OauthStateToken',
],
'guest'
Expand Down Expand Up @@ -218,6 +221,9 @@ public function testShowAuthPickerPageWithOauth() {
->expects($this->once())
->method('getServerHost')
->willReturn('example.com');
$this->request
->method('getServerProtocol')
->willReturn('https');

$expected = new TemplateResponse(
'core',
Expand All @@ -228,7 +234,7 @@ public function testShowAuthPickerPageWithOauth() {
'instanceName' => 'ExampleCloud',
'urlGenerator' => $this->urlGenerator,
'stateToken' => 'StateToken',
'serverHost' => 'example.com',
'serverHost' => 'https://example.com',
'oauthState' => 'OauthStateToken',
],
'guest'
Expand Down