mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	Implemented device code grant
This commit is contained in:
		@@ -6,9 +6,9 @@ namespace common\components\OAuth2;
 | 
			
		||||
use Carbon\CarbonInterval;
 | 
			
		||||
use DateInterval;
 | 
			
		||||
use League\OAuth2\Server\AuthorizationServer;
 | 
			
		||||
use yii\base\Component as BaseComponent;
 | 
			
		||||
use Yii;
 | 
			
		||||
 | 
			
		||||
final class AuthorizationServerFactory extends BaseComponent {
 | 
			
		||||
final class AuthorizationServerFactory {
 | 
			
		||||
 | 
			
		||||
    public static function build(): AuthorizationServer {
 | 
			
		||||
        $clientsRepo = new Repositories\ClientRepository();
 | 
			
		||||
@@ -17,6 +17,7 @@ final class AuthorizationServerFactory extends BaseComponent {
 | 
			
		||||
        $internalScopesRepo = new Repositories\InternalScopeRepository();
 | 
			
		||||
        $authCodesRepo = new Repositories\AuthCodeRepository();
 | 
			
		||||
        $refreshTokensRepo = new Repositories\RefreshTokenRepository();
 | 
			
		||||
        $deviceCodesRepo = new Repositories\DeviceCodeRepository();
 | 
			
		||||
 | 
			
		||||
        $accessTokenTTL = CarbonInterval::create(-1); // Set negative value to make tokens non expiring
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +43,12 @@ final class AuthorizationServerFactory extends BaseComponent {
 | 
			
		||||
        $authServer->enableGrantType($clientCredentialsGrant, $accessTokenTTL);
 | 
			
		||||
        $clientCredentialsGrant->setScopeRepository($internalScopesRepo); // Change repository after enabling
 | 
			
		||||
 | 
			
		||||
        $verificationUri = Yii::$app->request->getHostInfo() . '/code';
 | 
			
		||||
        $deviceCodeGrant = new Grants\DeviceCodeGrant($deviceCodesRepo, $refreshTokensRepo, new DateInterval('PT10M'), $verificationUri);
 | 
			
		||||
        $deviceCodeGrant->setIntervalVisibility(true);
 | 
			
		||||
        $authServer->enableGrantType($deviceCodeGrant, $accessTokenTTL);
 | 
			
		||||
        $deviceCodeGrant->setScopeRepository($publicScopesRepo); // Change repository after enabling
 | 
			
		||||
 | 
			
		||||
        return $authServer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user