mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
Merge pull request #3227 from wallabag/oauth-client-credentials
Add client_credentials oAuth2 auth method
This commit is contained in:
commit
d0702f9fbd
2 changed files with 25 additions and 4 deletions
|
@ -43,7 +43,7 @@ class DeveloperController extends Controller
|
||||||
$clientForm->handleRequest($request);
|
$clientForm->handleRequest($request);
|
||||||
|
|
||||||
if ($clientForm->isSubmitted() && $clientForm->isValid()) {
|
if ($clientForm->isSubmitted() && $clientForm->isValid()) {
|
||||||
$client->setAllowedGrantTypes(['token', 'authorization_code', 'password', 'refresh_token']);
|
$client->setAllowedGrantTypes(['client_credentials', 'token', 'authorization_code', 'password', 'refresh_token']);
|
||||||
$em->persist($client);
|
$em->persist($client);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
|
||||||
$this->assertContains('My app', $alert[0]);
|
$this->assertContains('My app', $alert[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateToken()
|
public function testCreateTokenFromPasswords()
|
||||||
{
|
{
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
$apiClient = $this->createApiClientForUser('admin');
|
$apiClient = $this->createApiClientForUser('admin');
|
||||||
|
@ -56,6 +56,26 @@ class DeveloperControllerTest extends WallabagCoreTestCase
|
||||||
$this->assertArrayHasKey('refresh_token', $data);
|
$this->assertArrayHasKey('refresh_token', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateTokenFromClientCredentialsOnly()
|
||||||
|
{
|
||||||
|
$client = $this->getClient();
|
||||||
|
$apiClient = $this->createApiClientForUser('admin', ['client_credentials']);
|
||||||
|
|
||||||
|
$client->request('POST', '/oauth/v2/token', [
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'client_id' => $apiClient->getPublicId(),
|
||||||
|
'client_secret' => $apiClient->getSecret(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||||
|
|
||||||
|
$data = json_decode($client->getResponse()->getContent(), true);
|
||||||
|
$this->assertArrayHasKey('access_token', $data);
|
||||||
|
$this->assertArrayHasKey('expires_in', $data);
|
||||||
|
$this->assertArrayHasKey('token_type', $data);
|
||||||
|
// Client Credentials created-clients have no refresh tokens
|
||||||
|
}
|
||||||
|
|
||||||
public function testListingClient()
|
public function testListingClient()
|
||||||
{
|
{
|
||||||
$this->logInAs('admin');
|
$this->logInAs('admin');
|
||||||
|
@ -114,9 +134,10 @@ class DeveloperControllerTest extends WallabagCoreTestCase
|
||||||
/**
|
/**
|
||||||
* @param string $username
|
* @param string $username
|
||||||
*
|
*
|
||||||
|
* @param array $grantTypes
|
||||||
* @return Client
|
* @return Client
|
||||||
*/
|
*/
|
||||||
private function createApiClientForUser($username)
|
private function createApiClientForUser($username, $grantTypes = ['password'])
|
||||||
{
|
{
|
||||||
$client = $this->getClient();
|
$client = $this->getClient();
|
||||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||||
|
@ -124,7 +145,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
|
||||||
$user = $userManager->findUserBy(array('username' => $username));
|
$user = $userManager->findUserBy(array('username' => $username));
|
||||||
$apiClient = new Client($user);
|
$apiClient = new Client($user);
|
||||||
$apiClient->setName('My app');
|
$apiClient->setName('My app');
|
||||||
$apiClient->setAllowedGrantTypes(['password']);
|
$apiClient->setAllowedGrantTypes($grantTypes);
|
||||||
$em->persist($apiClient);
|
$em->persist($apiClient);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue