authentifier()['jeton']; } public function projetId(): string { return $this->authentifier()['projet_id']; } /** * @return array{jeton: string, projet_id: string} */ private function authentifier(): array { return Cache::remember('openstack.authentification', now()->addMinutes(50), function () { $reponse = Http::post(config('openstack.auth_url').'/v3/auth/tokens', [ 'auth' => [ 'identity' => [ 'methods' => ['password'], 'password' => [ 'user' => [ 'name' => config('openstack.username'), 'domain' => ['id' => 'default'], 'password' => config('openstack.password'), ], ], ], 'scope' => [ 'project' => [ 'name' => config('openstack.project_name'), 'domain' => ['id' => 'default'], ], ], ], ]); if ($reponse->failed()) { throw new RuntimeException('Authentification OpenStack refusée : '.$reponse->body()); } return [ 'jeton' => $reponse->header('X-Subject-Token'), 'projet_id' => $reponse->json('token.project.id'), ]; }); } }