55namespace App \Services ;
66
77use GuzzleHttp \Client ;
8+ use GuzzleHttp \Exception \GuzzleException ;
89
910class DemoService
1011{
1112 /**
1213 * The paths to the mTLS certificate and key. These are used to authenticate with the PRS and NVI.
13- * @var string
1414 */
1515 protected string $ mtls_cert ;
16+
1617 /***
1718 * The paths to the mTLS certificate and key. These are used to authenticate with the PRS and NVI.
18- * @var string
1919 */
2020 protected string $ mtls_key ;
2121
2222 /**
2323 * The verify option for Guzzle. This can be set to false to disable SSL verification, or it can
2424 * be set to a path to a CA bundle.
25- *
26- * @var string|bool
2725 */
2826 protected string |bool $ verify ;
2927
@@ -36,9 +34,8 @@ public function __construct(string $mtls_cert, string $mtls_key, string|bool $ve
3634
3735 /**
3836 * Retrieves an OAuth token for the given URL (audience)
39- * @param string $url
40- * @return string
41- * @throws \GuzzleHttp\Exception\GuzzleException
37+ *
38+ * @throws GuzzleException
4239 */
4340 public function getOauthToken (string $ url ): string
4441 {
@@ -49,26 +46,24 @@ public function getOauthToken(string $url): string
4946 'verify ' => $ this ->verify ,
5047 ]);
5148
52- $ response = $ client ->post ('/ oauth/token ' , [
49+ $ response = $ client ->post ('oauth/token ' , [
5350 'form_params ' => [
54- 'target_audience ' => $ url ,
51+ 'target_audience ' => rtrim ( $ url, ' / ' ) ,
5552 'grant_type ' => 'client_credentials ' ,
5653 'scope ' => 'epd:read ' ,
5754 ],
5855 ]);
5956
6057 $ data = json_decode ((string ) $ response ->getBody (), true );
58+
6159 return $ data ['access_token ' ];
6260 }
6361
6462 /**
6563 * This creates a blinded input for a given hashed BSN. We do this by calling a test endpoint on the PRS, since PHP
6664 * does not have the necessary cryptographic libraries to do this locally.
6765 *
68- * @param string $token
69- * @param string $hashed_bsn
70- * @return array
71- * @throws \GuzzleHttp\Exception\GuzzleException
66+ * @throws GuzzleException
7267 */
7368 public function createPrsInput (string $ token , string $ hashed_bsn ): array
7469 {
@@ -79,7 +74,7 @@ public function createPrsInput(string $token, string $hashed_bsn): array
7974 'verify ' => $ this ->verify ,
8075 ]);
8176
82- $ response = $ client ->post ('/ test/oprf/client ' , [
77+ $ response = $ client ->post ('test/oprf/client ' , [
8378 'headers ' => [
8479 'Authorization ' => "Bearer $ token " ,
8580 ],
@@ -88,16 +83,13 @@ public function createPrsInput(string $token, string $hashed_bsn): array
8883 ],
8984 ]);
9085
91- return json_decode ((string )$ response ->getBody (), true );
86+ return json_decode ((string ) $ response ->getBody (), true );
9287 }
9388
9489 /**
9590 * Evaluate the blinded input with the PRS and return the result.
9691 *
97- * @param string $token
98- * @param string $input
99- * @return array
100- * @throws \GuzzleHttp\Exception\GuzzleException
92+ * @throws GuzzleException
10193 */
10294 public function prsEvaluate (string $ token , string $ input ): array
10395 {
@@ -108,7 +100,7 @@ public function prsEvaluate(string $token, string $input): array
108100 'verify ' => $ this ->verify ,
109101 ]);
110102
111- $ response = $ client ->post ('/ oprf/eval ' , [
103+ $ response = $ client ->post ('oprf/eval ' , [
112104 'headers ' => [
113105 'Authorization ' => "Bearer $ token " ,
114106 ],
@@ -119,17 +111,13 @@ public function prsEvaluate(string $token, string $input): array
119111 ],
120112 ]);
121113
122- return json_decode ((string )$ response ->getBody (), true );
114+ return json_decode ((string ) $ response ->getBody (), true );
123115 }
124116
125117 /**
126118 * Retrieves data from the NVI for a given token, eval_input and blind_factor.
127119 *
128- * @param string $token
129- * @param string $eval_input
130- * @param string $blind_factor
131- * @return array
132- * @throws \GuzzleHttp\Exception\GuzzleException
120+ * @throws GuzzleException
133121 */
134122 public function retrieveFromNVI (string $ token , string $ eval_input , string $ blind_factor ): array
135123 {
@@ -140,7 +128,7 @@ public function retrieveFromNVI(string $token, string $eval_input, string $blind
140128 'verify ' => $ this ->verify ,
141129 ]);
142130
143- $ response = $ client ->post ('/ Organization/$localize ' , [
131+ $ response = $ client ->post ('Organization/$localize ' , [
144132 'headers ' => [
145133 'Authorization ' => "Bearer $ token " ,
146134 ],
@@ -162,21 +150,18 @@ public function retrieveFromNVI(string $token, string $eval_input, string $blind
162150 'code ' => 'LaboratoryTestResult ' ,
163151 ],
164152 ],
165- ]
153+ ],
166154 ],
167155 ]);
168156
169- return json_decode ((string )$ response ->getBody (), true );
157+ return json_decode ((string ) $ response ->getBody (), true );
170158 }
171159
172-
173160 /**
174161 * Creates a NVIDataReference for the given BSN. This is used to demonstrate the full flow of creating a reference
175162 * in the NVI and then retrieving it.
176163 *
177- * @param string $bsn
178- * @return void
179- * @throws \GuzzleHttp\Exception\GuzzleException
164+ * @throws GuzzleException
180165 */
181166 public function createNVIDataReference (string $ bsn ): void
182167 {
@@ -197,15 +182,15 @@ public function createNVIDataReference(string $bsn): void
197182 'verify ' => $ this ->verify ,
198183 ]);
199184
200- $ client ->post ('/ NVIDataReference ' , [
185+ $ client ->post ('NVIDataReference ' , [
201186 'headers ' => [
202187 'Authorization ' => "Bearer $ token " ,
203188 ],
204189 'json ' => [
205190 'resourceType ' => 'NVIDataReference ' ,
206191 'source ' => [
207- 'system ' => " urn:oid:2.16.528.1.1007.3.3 " ,
208- 'value ' => " 90000206 "
192+ 'system ' => ' urn:oid:2.16.528.1.1007.3.3 ' ,
193+ 'value ' => config ( ' gfmodules.nvi.custodian_identifier_value ' ),
209194 ],
210195 'sourceType ' => [
211196 'coding ' => [
0 commit comments