mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-24 22:19:58 +05:30
Updated client credentials example
This commit is contained in:
parent
775d42115a
commit
9048617e35
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
|
|
||||||
include (__DIR__.'/../vendor/autoload.php');
|
|
||||||
|
|
||||||
// Setup the authorization server
|
|
||||||
$server = new \League\OAuth2\Server\Server();
|
|
||||||
$server->addRepository(new \OAuth2ServerExamples\Repositories\ClientRepository());
|
|
||||||
$server->addRepository(new \OAuth2ServerExamples\Repositories\ScopeRepository());
|
|
||||||
$server->addRepository(new \OAuth2ServerExamples\Repositories\AccessTokenRepository());
|
|
||||||
|
|
||||||
// Enable the client credentials grant which will return access tokens that last for 24 hours
|
|
||||||
$server->enableGrantType('ClientCredentialsGrant', null, new \DateInterval('PT24H'));
|
|
||||||
|
|
||||||
// Setup the routing
|
|
||||||
$application = new \Proton\Application();
|
|
||||||
$application->post('/access_token', function (Request $request) use ($server) {
|
|
||||||
return $server->getAccessTokenResponse($request);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Run the app
|
|
||||||
$application->run();
|
|
34
examples/public/client_credentials.php
Normal file
34
examples/public/client_credentials.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use League\OAuth2\Server\Exception\OAuthException;
|
||||||
|
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'));
|
||||||
|
|
||||||
|
// Setup 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();
|
Loading…
Reference in New Issue
Block a user