/** * @Given /^I have an OAuth access token$/ */ public function iHaveAnOauthAccessToken() { $params = array('grant_type' => 'client_credentials', 'client_id' => $this->app->getPublicId(), 'client_secret' => $this->app->getSecret()); $this->getClient()->request('GET', '/oauth/v2/token', $params); $data = json_decode($this->getClient()->getResponse()->getContent()); $this->access_token = $data->access_token; }
public function performOAuthUserLogin($scope) { $params = array('client_id' => $this->app->getPublicId(), 'response_type' => 'code', 'redirect_uri' => '/authenticate', 'scope' => $scope); $crawler = $this->userClient->request('GET', '/oauth/v2/auth', $params); $form = $crawler->selectButton('Allow')->form(); $this->userClient->followRedirects(false); $this->userClient->submit($form); $parts = parse_url($this->userClient->getResponse()->headers->get('location')); parse_str($parts['query'], $query); $code = $query['code']; $params = array('client_id' => $this->app->getPublicId(), 'client_secret' => $this->app->getSecret(), 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => '/authenticate'); $this->client->request('GET', '/oauth/v2/token', $params); $response = $this->client->getResponse(); $data = json_decode($response->getContent(), true); return $data['access_token']; }