Skip to content

Fixed authorizations api #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/Github/Api/Authorizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function remove($id)

public function check($id, $token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming id to clientId to be more explicit about which id it is (the github doc describes it as client_id btw): https://developer.github.com/v3/oauth_authorizations/#check-an-authorization

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell rename please it would be clear

{
return $this->get('authorizations/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
return $this->get('applications/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
}

public function revoke($id, $token)
{
return $this->delete('applications/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
}

public function revokeAll($id)
{
return $this->delete('applications/'.rawurlencode($id).'/tokens');
}
}
37 changes: 36 additions & 1 deletion test/Github/Tests/Api/AuthorizationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,47 @@ public function shouldCheckAuthorization()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('authorizations/'.$id.'/tokens/'.$token)
->with('applications/'.$id.'/tokens/'.$token)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->check($id, $token));
}

/**
* @test
*/
public function shouldRevokeAuthorization()
{
$id = 123;
$token = 'abc';
$expectedArray = array('id' => $id);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('applications/'.$id.'/tokens/'.$token)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->revoke($id, $token));
}

/**
* @test
*/
public function shouldRevokeAllAuthorizations()
{
$id = 123;
$expectedArray = array('id' => $id);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('applications/'.$id.'/tokens')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->revokeAll($id));
}

/**
* @test
*/
Expand Down