Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support for idtoken to get a webID from legacy style apps #45

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
39 changes: 38 additions & 1 deletion src/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@
use Pdsinterop\Solid\Auth\Utils\DPop as DPop;
use Pdsinterop\Solid\Auth\WAC as WAC;

class idToken {
public function getWebId($request) {
$auth = explode(" ", $request->getServerParams()['HTTP_AUTHORIZATION']);
$jwt = $auth[1];

if (strtolower($auth[0]) == "dpop") {
return DPop::getWebId($request);
}

if ($jwt) {
$webId = $this->getSubjectFromJwt($jwt);
} else {
$webId = "public";
}

return $webId;
}

public function getSubjectFromJwt($jwt) {
$parser = new \Lcobucci\JWT\Parser();
try {
$jwt = $parser->parse($jwt);
} catch(\Exception $e) {
return $this->server->getResponse()->withStatus(409, "Invalid JWT token");
}

if ($jwt->getClaim("token_type") == "pop") {
$idToken = $jwt->getClaim("id_token");
$idt = $parser->parse($idToken);
return $idt->getClaim("sub");
} else {
return $jwt->getClaim("sub");
}
}
}

class ResourceController extends AbstractController
{
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
Expand All @@ -26,6 +62,7 @@ final public function __construct(Server $server)
$this->baseUrl = isset($_ENV['SERVER_ROOT']) ? $_ENV['SERVER_ROOT'] : "https://localhost";
$this->server = $server;
$this->DPop = new DPop();
$this->idToken = new idToken();
$this->WAC = new WAC($server->getFilesystem());

// Make sure the root folder has an acl file, as is required by the spec;
Expand All @@ -39,7 +76,7 @@ final public function __construct(Server $server)
final public function __invoke(Request $request, array $args) : Response
{
try {
$webId = $this->DPop->getWebId($request);
$webId = $this->idToken->getWebId($request);
} catch(\Exception $e) {
return $this->server->getResponse()->withStatus(409, "Invalid token");
}
Expand Down