Auth0\SDK\API\Authentication::authorize_with_ro PHP Method

authorize_with_ro() public method

public authorize_with_ro ( $username, $password, $scope = 'openid', $connection = null, $id_token = null, $device = null )
    public function authorize_with_ro($username, $password, $scope = 'openid', $connection = null, $id_token = null, $device = null)
    {
        $data = ['client_id' => $this->client_id, 'username' => $username, 'password' => $password, 'scope' => $scope];
        if ($device !== null) {
            $data['device'] = $device;
        }
        if ($id_token !== null) {
            $data['id_token'] = $id_token;
            $data['grant_type'] = 'urn:ietf:params:oauth:grant-type:jwt-bearer';
        } else {
            if ($connection === null) {
                throw new ApiException('You need to specify a conection for grant_type=password authentication');
            }
            $data['grant_type'] = 'password';
            $data['connection'] = $connection;
        }
        return $this->apiClient->post()->oauth()->ro()->withHeader(new ContentType('application/json'))->withBody(json_encode($data))->call();
    }

Usage Example

Exemplo n.º 1
0
 public function testAuthorizeWithRO()
 {
     $env = $this->getEnv();
     $api = new Authentication($env['DOMAIN'], $env['APP_CLIENT_ID']);
     $response = $api->authorize_with_ro('*****@*****.**', '123456', 'openid', 'Username-Password-Authentication');
     $this->assertArrayHasKey('id_token', $response);
     $this->assertArrayHasKey('access_token', $response);
     $this->assertArrayHasKey('token_type', $response);
     $this->assertEquals('bearer', $response['token_type']);
     $userinfo = $api->userinfo($response['access_token']);
     $this->assertArrayHasKey('email', $userinfo);
     $this->assertArrayHasKey('email_verified', $userinfo);
     $this->assertArrayHasKey('user_id', $userinfo);
     $this->assertEquals('*****@*****.**', $userinfo['email']);
     $this->assertEquals('auth0|57e293c6247600bf0ba47fc2', $userinfo['user_id']);
     $tokeninfo = $api->tokeninfo($response['id_token']);
     $this->assertArrayHasKey('email', $tokeninfo);
     $this->assertArrayHasKey('email_verified', $tokeninfo);
     $this->assertArrayHasKey('user_id', $tokeninfo);
     $this->assertEquals('*****@*****.**', $tokeninfo['email']);
     $this->assertEquals('auth0|57e293c6247600bf0ba47fc2', $tokeninfo['user_id']);
 }