mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Checkin
This commit is contained in:
@@ -1,32 +1,20 @@
|
||||
<?php
|
||||
|
||||
use League\OAuth2\Server\Exception\OAuthException;
|
||||
use League\OAuth2\Server\Grant\ClientCredentialsGrant;
|
||||
use League\OAuth2\Server\Server;
|
||||
use OAuth2ServerExamples\Repositories\AccessTokenRepository;
|
||||
use OAuth2ServerExamples\Repositories\ClientRepository;
|
||||
use OAuth2ServerExamples\Repositories\ScopeRepository;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
include(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
// Setup the authorization server
|
||||
$server = new Server();
|
||||
$server->addRepository(new ClientRepository());
|
||||
$server->addRepository(new ScopeRepository());
|
||||
$server->addRepository(new AccessTokenRepository());
|
||||
|
||||
// Enable the client credentials grant which will return access tokens that last for 24 hours
|
||||
$server->enableGrantType('ClientCredentialsGrant', null, new \DateInterval('PT24H'));
|
||||
// Init our repositories
|
||||
$clientRepository = new ClientRepository();
|
||||
$scopeRepository = new ScopeRepository();
|
||||
$accessTokenRepository = new AccessTokenRepository();
|
||||
|
||||
// Setup app + routing
|
||||
$application = new \Proton\Application();
|
||||
$application->post('/access_token', function (Request $request) use ($server) {
|
||||
try {
|
||||
return $server->getAccessTokenResponse($request);
|
||||
} catch (OAuthException $e) {
|
||||
return $e->generateHttpResponse();
|
||||
}
|
||||
});
|
||||
|
||||
// Run the app
|
||||
$application->run();
|
||||
// Enable the client credentials grant on the server
|
||||
$server->enableGrantType(new ClientCredentialsGrant($clientRepository, $scopeRepository, $accessTokenRepository));
|
||||
|
Reference in New Issue
Block a user