Skip to content
Open
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
35 changes: 35 additions & 0 deletions src/Grant/DeviceCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Implements "device_code" for league/oauth2-client library
*
* @copyright Copyright (c) Sebastian Lemke
* @license http://opensource.org/licenses/MIT MIT
*/

namespace League\OAuth2\Client\Grant;

/**
* Represents a device authorization grant.
*
* @link https://tools.ietf.org/html/rfc8628
*/
class DeviceCode extends AbstractGrant
{
/**
* @inheritdoc
*/
protected function getName()
{
return 'urn:ietf:params:oauth:grant-type:device_code';
}

/**
* @inheritdoc
*/
protected function getRequiredRequestParameters()
{
return [
'device_code',
];
}
}
39 changes: 39 additions & 0 deletions test/src/Grant/DeviceCodeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace League\OAuth2\Client\Test\Grant;

use BadMethodCallException;
use League\OAuth2\Client\Grant\DeviceCode;

class DeviceCodeTest extends GrantTestCase
{
public static function providerGetAccessToken()
{
return [
['device_code', ['device_code' => 'mock_device_code']],
];
}

protected function getParamExpectation()
{
return function ($body) {
return !empty($body['grant_type'])
&& $body['grant_type'] === 'urn:ietf:params:oauth:grant-type:device_code'
&& !empty($body['device_code']);
};
}

public function testToString()
{
$grant = new DeviceCode();
$this->assertEquals('urn:ietf:params:oauth:grant-type:device_code', (string) $grant);
}

public function testInvalidDeviceCode()
{
$this->expectException(BadMethodCallException::class);

$this->getMockProvider()->getAccessToken('device_code', ['invalid_device_code' => 'mock_device_code']);
}

}