Skip to content

Commit

Permalink
Enable OIDC bearer token authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinash Gusain committed Oct 27, 2023
1 parent a4866d4 commit b03f922
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Util;
use OCA\OIDCLogin\WebDAV\BearerAuthBackend;

class Application extends App implements IBootstrap
{
Expand Down Expand Up @@ -66,6 +67,15 @@ public function boot(IBootContext $context): void

/** @var IRequest */
$request = $container->get(IRequest::class);
$bearerAuthBackend = $container->query(BearerAuthBackend::class);

// If it is an OCS request, try to authenticate with bearer token
if ($request->getHeader('OCS-APIREQUEST') === 'true' &&
$request->getHeader('OIDC-LOGIN-WITH-TOKEN') === 'true' &&
str_starts_with($request->getHeader('Authorization'), 'Bearer ')) {
$this->loginWithBearerToken($request, $bearerAuthBackend);
}


// Check if automatic redirection is enabled
$useLoginRedirect = $this->config->getSystemValue('oidc_login_auto_redirect', false);
Expand Down Expand Up @@ -155,4 +165,13 @@ public function boot(IBootContext $context): void
}
}
}

private function loginWithBearerToken(IRequest $request, BearerAuthBackend $bearerAuthBackend) {
$authHeader = $request->getHeader('Authorization');
$bearerToken = substr($authHeader, 7);
if (empty($bearerToken)) {
return;
}
$bearerAuthBackend->validateBearerToken($bearerToken);
}
}

0 comments on commit b03f922

Please sign in to comment.