clientSecret)) { throw new \RuntimeException( 'VIKON_CLIENT_SECRET не настроен. Обратитесь к администратору.' ); } $response = $this->callVikonApiTask->post('oauth2/authorize/token', [ 'code' => $code, 'client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'redirect_uri' => $redirectUri, 'grant_type' => 'authorization_code', ], [], 'auth'); $body = $response->json(); if (!isset($body['access_token']) || !isset($body['refresh_token'])) { throw new \RuntimeException( 'Authentication failed: ' . ($body['message'] ?? 'Unknown error') ); } return [ 'access_token' => $body['access_token'], 'refresh_token' => $body['refresh_token'], ]; } }