You are here

public function PasswordGrantTest::testThatPasswordGrantRealmLoginSetsForwardedForHeader in Auth0 Single Sign On 8.2

Test that a password grant request including an IP address sets the correct header.

Throws

ApiException If username or password is missing.

File

vendor/auth0/auth0-php/tests/API/Authentication/PasswordGrantTest.php, line 192

Class

PasswordGrantTest
Class PasswordGrantTest Tests the Authentication API class, specifically password grants.

Namespace

Auth0\Tests\API\Authentication

Code

public function testThatPasswordGrantRealmLoginSetsForwardedForHeader() {
  $api = new MockAuthenticationApi([
    new Response(200),
    new Response(200),
  ]);
  $api
    ->call()
    ->login([
    'username' => uniqid(),
    'password' => uniqid(),
    'realm' => uniqid(),
  ], '5.6.7.8');
  $request_headers = $api
    ->getHistoryHeaders();
  $this
    ->assertArrayHasKey('Auth0-Forwarded-For', $request_headers);
  $this
    ->assertEquals('5.6.7.8', $request_headers['Auth0-Forwarded-For'][0]);
  $api
    ->call()
    ->login([
    'username' => uniqid(),
    'password' => uniqid(),
    'realm' => uniqid(),
    'auth0_forwarded_for' => '5.6.7.8',
  ]);
  $request_headers = $api
    ->getHistoryHeaders();
  $this
    ->assertArrayHasKey('Auth0-Forwarded-For', $request_headers);
  $this
    ->assertEquals('5.6.7.8', $request_headers['Auth0-Forwarded-For'][0]);
}