Source of file DefaultGenerator.php
Size: 2,067 Bytes - Last Modified: 2022-02-21T10:00:46+00:00
/var/www/docs.ssmods.com/process/src/src/AuthorizationServer/DefaultGenerator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | <?php namespace AdvancedLearning\Oauth2Server\AuthorizationServer; use AdvancedLearning\Oauth2Server\Repositories\AccessTokenRepository; use AdvancedLearning\Oauth2Server\Repositories\ClientRepository; use AdvancedLearning\Oauth2Server\Repositories\RefreshTokenRepository; use AdvancedLearning\Oauth2Server\Repositories\ScopeRepository; use AdvancedLearning\Oauth2Server\Repositories\UserRepository; use League\OAuth2\Server\AuthorizationServer; use League\OAuth2\Server\Grant\ClientCredentialsGrant; use League\OAuth2\Server\Grant\PasswordGrant; use SilverStripe\Control\Director; use SilverStripe\Core\Environment; class DefaultGenerator implements Generator { /** * @inheritdoc */ public function getServer(): AuthorizationServer { // Init our repositories $clientRepository = new ClientRepository(); $scopeRepository = new ScopeRepository(); $accessTokenRepository = new AccessTokenRepository(); $userRepository = new UserRepository(); $refreshRepository = new RefreshTokenRepository(); // Path to public and private keys $privateKey = Environment::getEnv('OAUTH_PRIVATE_KEY_PATH'); // inject base bath if necessary $privateKey = str_replace('{BASE_DIR}', Director::baseFolder(), $privateKey); $encryptionKey = Environment::getEnv('OAUTH_ENCRYPTION_KEY'); // Setup the authorization server $server = new AuthorizationServer( $clientRepository, $accessTokenRepository, $scopeRepository, $privateKey, $encryptionKey ); // Enable the client credentials grant on the server $server->enableGrantType( new ClientCredentialsGrant(), new \DateInterval('PT1H') // access tokens will expire after 1 hour ); // Enable password grant $server->enableGrantType( new PasswordGrant($userRepository, $refreshRepository), new \DateInterval('PT1H') ); return $server; } } |