Subversion Repositories eFlore/Applications.cel

Rev

Rev 3959 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3959 Rev 3967
Line 184... Line 184...
184
		
184
		
185
		if ($cookie){
185
		if ($cookie){
186
			// Récupération de l'id et email de l'utilisateur connecté
186
			// Récupération de l'id et email de l'utilisateur connecté
Line -... Line 187...
-
 
187
			$tokenInfos = $this->decodeToken($cookie);
187
			$tokenInfos = $this->decodeToken($cookie);
188
			
188
			
189
			$token = $this->refreshToken($cookie)['token'];
189
			$service = "auth/identite?token=";
190
//			$service = "auth/identite?token=";
190
			$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service).$cookie;
191
//			$url = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service).$cookie;
191
			
192
//
192
			$json = $this->getDao()->consulter($url);
193
//			$json = $this->getDao()->consulter($url);
193
			$token = json_decode($json, true)['token'];
194
//			$token = json_decode($json, true)['token'];
194
			
195
 
195
			$user = [
196
			$user = [
196
				'id' => $tokenInfos['id'],
197
				'id' => $tokenInfos['id'],
197
				'email' => $tokenInfos['sub'],
198
				'email' => $tokenInfos['sub'],
Line 198... Line 199...
198
				'token' => $token
199
				'token' => $token
199
			];
200
			];
Line 200... Line 201...
200
			
201
			
-
 
202
			return $user;
-
 
203
		}
-
 
204
		
-
 
205
	}
-
 
206
	
-
 
207
	protected function refreshToken($token) {
-
 
208
//		$verificationServiceURL = 'https://www.tela-botanica.org/service:annuaire:auth/identite';
-
 
209
		$service = "auth/identite?token=" . $token;
-
 
210
		$verificationServiceURL = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], $service);
-
 
211
//		$verificationServiceURL .= "?token=" . $token;
-
 
212
		$ch = curl_init();
-
 
213
//		$timeout = 5;
-
 
214
		$cookie = 'tb_auth='.$token;
-
 
215
		
-
 
216
		$headr = array();
-
 
217
		$headr[] = 'Cookie: ' . $cookie;
-
 
218
		$headr[] = 'Authorization: '.$token;
-
 
219
		
-
 
220
		curl_setopt($ch, CURLOPT_URL, $verificationServiceURL);
-
 
221
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
-
 
222
		curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
-
 
223
//		curl_setopt($ch, CURLOPT_HTTPHEADER, [
-
 
224
//			'Cookie: ' . $cookie,
-
 
225
//		]);
-
 
226
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
-
 
227
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
 
228
//		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
-
 
229
		// équivalent de "-k"
-
 
230
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
-
 
231
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
-
 
232
		$response = curl_exec($ch);
-
 
233
		
-
 
234
//		if ($response === false) {
-
 
235
//			echo 'Erreur cURL : ' . curl_error($ch);
-
 
236
//		} else {
-
 
237
//			echo 'Réponse : ' . $response;
-
 
238
//		}
-
 
239
		
Line 201... Line 240...
201
			return $user;
240
		curl_close($ch);
202
		}
241
 
203
		
242
		return json_decode($response, true);
204
	}
243
	}