AuthBucket\Bundle\OAuth2Bundle\Tests\OAuth2Test::testClientCredentialsGrant PHP Method

testClientCredentialsGrant() public method

    public function testClientCredentialsGrant()
    {
        // Query the token endpoint with grant_type = client_credentials.
        $parameters = ['grant_type' => 'client_credentials', 'scope' => 'demoscope1 demoscope2 demoscope3'];
        $server = ['PHP_AUTH_USER' => 'http://democlient1.com/', 'PHP_AUTH_PW' => 'demosecret1'];
        $client = $this->createClient();
        $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server);
        $this->assertNotNull(json_decode($client->getResponse()->getContent()));
        // Query token endpoint with grant_type = refresh_token.
        $tokenResponse = json_decode($client->getResponse()->getContent(), true);
        $parameters = ['grant_type' => 'refresh_token', 'refresh_token' => $tokenResponse['refresh_token'], 'scope' => 'demoscope1 demoscope2 demoscope3'];
        $server = ['PHP_AUTH_USER' => 'http://democlient1.com/', 'PHP_AUTH_PW' => 'demosecret1'];
        $client = $this->createClient();
        $crawler = $client->request('POST', '/api/oauth2/token', $parameters, [], $server);
        // Check basic token response that can simply compare.
        $tokenResponse = json_decode($client->getResponse()->getContent(), true);
        $this->assertSame('bearer', $tokenResponse['token_type']);
        $this->assertSame('demoscope1 demoscope2 demoscope3', $tokenResponse['scope']);
        // Query debug endpoint with access_token.
        $parameters = [];
        $server = ['HTTP_Authorization' => implode(' ', ['Bearer', $tokenResponse['access_token']])];
        $client = $this->createClient();
        $crawler = $client->request('GET', '/api/oauth2/debug', $parameters, [], $server);
        $debugResponse = json_decode($client->getResponse()->getContent(), true);
        $this->assertSame('', $debugResponse['username']);
    }