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

testResourceOwnerPasswordCredentialsGrant() public method

    public function testResourceOwnerPasswordCredentialsGrant()
    {
        // Query the token endpoint with grant_type = password.
        $parameters = ['grant_type' => 'password', 'username' => 'demousername1', 'password' => 'demopassword1', 'scope' => 'demoscope1'];
        $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'];
        $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', $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('demousername1', $debugResponse['username']);
    }