@@ -17,9 +17,9 @@ abstract class ServerController extends AbstractController
1717 public function __construct ()
1818 {
1919 $ this ->config = new \Pdsinterop \Solid \ServerConfig (__DIR__ .'/../../config/ ' );
20-
21- $ this ->authServerConfig = $ this ->createAuthServerConfig ();
22- $ this ->authServerFactory = (new \Pdsinterop \Solid \Auth \Factory \AuthorizationServerFactory ($ this ->authServerConfig ))->create ();
20+
21+ $ this ->authServerConfig = $ this ->createAuthServerConfig ();
22+ $ this ->authServerFactory = (new \Pdsinterop \Solid \Auth \Factory \AuthorizationServerFactory ($ this ->authServerConfig ))->create ();
2323 $ this ->tokenGenerator = (new \Pdsinterop \Solid \Auth \TokenGenerator ($ this ->authServerConfig ));
2424 $ this ->baseUrl = isset ($ _ENV ['SERVER_ROOT ' ]) ? $ _ENV ['SERVER_ROOT ' ] : "https://localhost " ;
2525 }
@@ -39,98 +39,107 @@ public function getOpenIdEndpoints() {
3939 ];
4040 }
4141
42- public function getKeys () {
43- $ encryptionKey = $ this ->config ->getEncryptionKey ();
44- $ privateKey = $ this ->config ->getPrivateKey ();
45- $ key = openssl_pkey_get_private ($ privateKey );
46- $ publicKey = openssl_pkey_get_details ($ key )['key ' ];
47- return [
48- "encryptionKey " => $ encryptionKey ,
49- "privateKey " => $ privateKey ,
50- "publicKey " => $ publicKey
51- ];
52- }
42+ public function getKeys ()
43+ {
44+ $ encryptionKey = $ this ->config ->getEncryptionKey ();
45+ $ privateKey = $ this ->config ->getPrivateKey ();
46+ $ key = openssl_pkey_get_private ($ privateKey );
47+ $ publicKey = openssl_pkey_get_details ($ key )['key ' ];
5348
54- public function createAuthServerConfig () {
55- $ clientId = $ _GET ['client_id ' ]; // FIXME: No request object here to get the client Id from.
56- $ client = $ this ->getClient ($ clientId );
57- $ keys = $ this ->getKeys ();
58- try {
59- $ config = (new \Pdsinterop \Solid \Auth \Factory \ConfigFactory (
60- $ client ,
61- $ keys ['encryptionKey ' ],
62- $ keys ['privateKey ' ],
63- $ keys ['publicKey ' ],
64- $ this ->getOpenIdEndpoints ()
65- ))->create ();
66- } catch (\Throwable $ e ) {
67- // var_dump($e);
68- }
69- return $ config ;
70- }
49+ return [
50+ "encryptionKey " => $ encryptionKey ,
51+ "privateKey " => $ privateKey ,
52+ "publicKey " => $ publicKey ,
53+ ];
54+ }
7155
72- public function getClient ($ clientId ) {
73- $ clientRegistration = $ this ->config ->getClientRegistration ($ clientId );
74-
75- if ($ clientId && sizeof ($ clientRegistration )) {
76- return new \Pdsinterop \Solid \Auth \Config \Client (
77- $ clientId ,
78- $ clientRegistration ['client_secret ' ],
79- $ clientRegistration ['redirect_uris ' ],
80- $ clientRegistration ['client_name ' ]
81- );
82- } else {
83- return new \Pdsinterop \Solid \Auth \Config \Client ('' ,'' ,array (),'' );
84- }
85- }
56+ public function createAuthServerConfig ()
57+ {
58+ $ clientId = $ _GET ['client_id ' ]; // FIXME: No request object here to get the client Id from.
59+ $ client = $ this ->getClient ($ clientId );
60+ $ keys = $ this ->getKeys ();
61+ try {
62+ $ config = (new ConfigFactory (
63+ $ client ,
64+ $ keys ['encryptionKey ' ],
65+ $ keys ['privateKey ' ],
66+ $ keys ['publicKey ' ],
67+ $ this ->getOpenIdEndpoints ()
68+ ))->create ();
69+ } catch (Throwable $ e ) {
70+ // var_dump($e);
71+ }
8672
87- public function createConfig ($ baseUrl ) {
88- // if (isset($_GET['client_id'])) {
89- $ clientId = $ _GET ['client_id ' ];
90- $ client = $ this ->getClient ($ clientId , $ baseUrl );
91- // }
92- try {
93- $ config = (new \Pdsinterop \Solid \Auth \Factory \ConfigFactory (
94- $ client ,
95- $ this ->keys ['encryptionKey ' ],
96- $ this ->keys ['privateKey ' ],
97- $ this ->keys ['publicKey ' ],
98- $ this ->openIdConfiguration
99- ))->create ();
100- } catch (\Throwable $ e ) {
101- var_dump ($ e );
102- }
103- return $ config ;
104- }
105-
106- public function checkApproval ($ clientId ) {
107- $ allowedClients = $ this ->config ->getAllowedClients ($ this ->userId );
108- if ($ clientId == md5 ("tester " )) { // FIXME: Double check that this is not a security issue; It is only here to help the test suite;
109- return \Pdsinterop \Solid \Auth \Enum \Authorization::APPROVED ;
110- }
111- if (in_array ($ clientId , $ allowedClients )) {
112- return \Pdsinterop \Solid \Auth \Enum \Authorization::APPROVED ;
113- } else {
114- return \Pdsinterop \Solid \Auth \Enum \Authorization::DENIED ;
115- }
116- }
117-
118- public function getProfilePage () {
119- return $ this ->baseUrl . "/profile/card#me " ; // FIXME: would be better to base this on the available routes if possible.
120- }
121-
122- public function getResponseType () {
73+ return $ config ;
74+ }
75+
76+ public function getClient ($ clientId )
77+ {
78+ $ clientRegistration = $ this ->config ->getClientRegistration ($ clientId );
79+
80+ if ($ clientId && count ($ clientRegistration )) {
81+ $ client = new Client (
82+ $ clientId ,
83+ $ clientRegistration ['client_secret ' ],
84+ $ clientRegistration ['redirect_uris ' ],
85+ $ clientRegistration ['client_name ' ]
86+ );
87+ } else {
88+ $ client = new Client ('' , '' , [], '' );
89+ }
90+
91+ return $ client ;
92+ }
93+
94+ public function createConfig ()
95+ {
96+ // if (isset($_GET['client_id'])) {
97+ $ clientId = $ _GET ['client_id ' ];
98+ $ client = $ this ->getClient ($ clientId );
99+
100+ // }
101+ return (new ConfigFactory (
102+ $ client ,
103+ $ this ->keys ['encryptionKey ' ],
104+ $ this ->keys ['privateKey ' ],
105+ $ this ->keys ['publicKey ' ],
106+ $ this ->openIdConfiguration
107+ ))->create ();
108+ }
109+ public function checkApproval ($ clientId )
110+ {
111+ $ approval = Authorization::DENIED ;
112+
113+ $ allowedClients = $ this ->config ->getAllowedClients ($ this ->userId );
114+
115+ if (
116+ $ clientId === md5 ("tester " ) // FIXME: Double check that this is not a security issue; It is only here to help the test suite;
117+ || in_array ($ clientId , $ allowedClients , true )
118+ ) {
119+ $ approval = Authorization::APPROVED ;
120+ }
121+
122+ return $ approval ;
123+ }
124+ public function getProfilePage () : string
125+ {
126+ return $ this ->baseUrl . "/profile/card#me " ; // FIXME: would be better to base this on the available routes if possible.
127+ }
128+
129+ public function getResponseType () : string
130+ {
123131 $ responseTypes = explode (" " , $ _GET ['response_type ' ] ?? '' );
124- foreach ($ responseTypes as $ responseType ) {
125- switch ($ responseType ) {
126- case "token " :
127- return "token " ;
128- break ;
129- case "code " :
130- return "code " ;
131- break ;
132- }
133- }
134- return "token " ; // default to token response type;
135- }
132+ foreach ($ responseTypes as $ responseType ) {
133+ switch ($ responseType ) {
134+ case "token " :
135+ return "token " ;
136+ break ;
137+ case "code " :
138+ return "code " ;
139+ break ;
140+ }
141+ }
142+
143+ return "token " ; // default to token response type;
144+ }
136145}
0 commit comments