@@ -28,10 +28,10 @@ class DPop {
2828
2929 private JtiValidator $ jtiValidator ;
3030
31- public function __construct (JtiValidator $ jtiValidator )
32- {
33- $ this ->jtiValidator = $ jtiValidator ;
34- }
31+ public function __construct (JtiValidator $ jtiValidator )
32+ {
33+ $ this ->jtiValidator = $ jtiValidator ;
34+ }
3535
3636 /**
3737 * This method fetches the WebId from a request and verifies
@@ -48,29 +48,28 @@ public function __construct(JtiValidator $jtiValidator)
4848 public function getWebId ($ request ) {
4949 $ serverParams = $ request ->getServerParams ();
5050
51- $ this ->validateRequestHeaders ($ serverParams );
52-
53- [, $ jwt ] = explode (" " , $ serverParams ['HTTP_AUTHORIZATION ' ], 2 );
51+ if (isset ($ serverParams ['HTTP_AUTHORIZATION ' ]) === false ) {
52+ $ webId = "public " ;
53+ } else {
54+ $ this ->validateRequestHeaders ($ serverParams );
5455
55- $ dpop = $ serverParams ['HTTP_DPOP ' ] ;
56+ [, $ jwt ] = explode ( " " , $ serverParams ['HTTP_AUTHORIZATION ' ], 2 ) ;
5657
57- //@FIXME: check that there is just one DPoP token in the request
58- try {
59- $ dpopKey = $ this ->getDpopKey ($ dpop , $ request );
60- } catch (InvalidTokenStructure $ e ) {
61- throw new InvalidTokenException ("Invalid JWT token: {$ e ->getMessage ()}" , 0 , $ e );
62- }
58+ $ dpop = $ serverParams ['HTTP_DPOP ' ];
6359
64- try {
65- $ this ->validateJwtDpop ($ jwt , $ dpopKey );
66- } catch (RequiredConstraintsViolated $ e ) {
67- throw new InvalidTokenException ($ e ->getMessage (), 0 , $ e );
68- }
60+ //@FIXME: check that there is just one DPoP token in the request
61+ try {
62+ $ dpopKey = $ this ->getDpopKey ($ dpop , $ request );
63+ } catch (InvalidTokenStructure $ e ) {
64+ throw new InvalidTokenException ("Invalid JWT token: {$ e ->getMessage ()}" , 0 , $ e );
65+ }
6966
70- if ($ jwt ) {
67+ try {
68+ $ this ->validateJwtDpop ($ jwt , $ dpopKey );
69+ } catch (RequiredConstraintsViolated $ e ) {
70+ throw new InvalidTokenException ($ e ->getMessage (), 0 , $ e );
71+ }
7172 $ webId = $ this ->getSubjectFromJwt ($ jwt );
72- } else {
73- $ webId = "public " ;
7473 }
7574
7675 return $ webId ;
@@ -274,10 +273,6 @@ private function getSubjectFromJwt($jwt) {
274273 }
275274
276275 private function validateRequestHeaders ($ serverParams ) {
277- if (isset ($ serverParams ['HTTP_AUTHORIZATION ' ]) === false ) {
278- throw new AuthorizationHeaderException ("Authorization Header missing " );
279- }
280-
281276 if (str_contains ($ serverParams ['HTTP_AUTHORIZATION ' ], ' ' ) === false ) {
282277 throw new AuthorizationHeaderException ("Authorization Header does not contain parameters " );
283278 }
0 commit comments