setVariable() public méthode

Sets a persistent variable.
public setVariable ( string $name, mixed $value ) : OAuth2
$name string The name of the variable to set.
$value mixed The value to set.
Résultat OAuth2 The application (for chained calls of this method)
 /**
  * Tests OAuth2->grantAccessToken() with successful Auth code grant, but without redreict_uri in the input
  */
 public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect()
 {
     $request = new Request(array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code' => 'foo'));
     $storedToken = new OAuth2AuthCode('my_little_app', '', time() + 60, null, null, 'http://www.example.com');
     $mockStorage = $this->createBaseMock('OAuth2\\IOAuth2GrantCode');
     $mockStorage->expects($this->any())->method('getAuthCode')->will($this->returnValue($storedToken));
     $this->fixture = new OAuth2($mockStorage);
     $this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, false);
     $response = $this->fixture->grantAccessToken($request);
     // Successful token grant will return a JSON encoded token:
     $this->assertRegexp('/{"access_token":".*","expires_in":\\d+,"token_type":"bearer"/', $response->getContent());
 }
Exemple #2
0
 /**
  * Tests OAuth2->grantAccessToken() with Auth code grant
  *
  */
 public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams()
 {
     $mockStorage = $this->createBaseMock('OAuth2\\IOAuth2GrantCode');
     $mockStorage->expects($this->any())->method('getClient')->will($this->returnValue(new OAuth2Client('dev-abc')));
     $mockStorage->expects($this->any())->method('checkClientCredentials')->will($this->returnValue(true));
     // Always return true for any combination of user/pass
     $inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b');
     $fakeAuthCode = array('client_id' => $inputData['client_id'], 'redirect_uri' => '/foo', 'expires' => time() + 60);
     $fakeAccessToken = array('access_token' => 'abcde');
     // Ensure redirect URI and auth-code is mandatory
     try {
         $this->fixture = new OAuth2($mockStorage);
         $this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, true);
         // Only required when this is set
         $request = $this->createRequest($inputData + array('code' => 'foo'));
         $this->fixture->grantAccessToken($request);
         $this->fail('The expected exception OAuth2ServerException was not thrown');
     } catch (OAuth2ServerException $e) {
         $this->assertEquals(OAuth2::ERROR_INVALID_REQUEST, $e->getMessage());
     }
     try {
         $this->fixture = new OAuth2($mockStorage);
         $request = $this->createRequest($inputData + array('redirect_uri' => 'foo'));
         $this->fixture->grantAccessToken($request);
         $this->fail('The expected exception OAuth2ServerException was not thrown');
     } catch (OAuth2ServerException $e) {
         $this->assertEquals(OAuth2::ERROR_INVALID_REQUEST, $e->getMessage());
     }
 }