Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krakphp/doctrine-oauth2
Doctrine and Laravel OAuth2 Integrations
https://github.com/krakphp/doctrine-oauth2
doctrine-orm laravel oauth2
Last synced: about 1 month ago
JSON representation
Doctrine and Laravel OAuth2 Integrations
- Host: GitHub
- URL: https://github.com/krakphp/doctrine-oauth2
- Owner: krakphp
- License: mit
- Created: 2018-02-12T23:59:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-17T04:49:06.000Z (almost 7 years ago)
- Last Synced: 2024-11-14T01:23:27.213Z (2 months ago)
- Topics: doctrine-orm, laravel, oauth2
- Language: PHP
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Doctrine OAuth2
This library provides OAuth2 integration for Doctrine and Laravel. It uses the `league/oauth2-server` package for all of the heavy lifting and the Doctrine ORM for the backend.
## Installation
Install with composer at `krak/doctrine-oauth2`
## Laravel Usage
```php
register(LaravelDoctrine\ORM\DoctrineServiceProvider::class);
$app->register(LaravelDoctrine\Migrations\MigrationsServiceProvider::class);
$app->register(Krak\DoctrineOAuth2\OAuth2ServiceProvider::class);$app['oauth2.seeds']->push(function($em, $logger) {
$scopes = [
new Scope('basic', 'Basic', 'Allows basic access to the API.'),
new Scope('user', 'User', 'Allows user access to the API.'),
];$logger->info("Creating local client");
$client = new Client('local', 'local', 'local123', '', $scopes);
$em->persist($client);
foreach ($scopes as $scope) {
$logger->info("Creating scope: ". json_encode($scope, JSON_PRETTY_PRINT));
$em->persist($scope);
}
});$app->router->group(['middleware' => 'oauth2'], function($router) {
$router->get('/', function(Illuminate\Http\Request $req) {
return $req->attributes->all();
});
});
``````php
[
'refresh_token',
'password',
'client_credentials',
'authorization_code',
'implicit'
],
'client_credentials' => [
'access_token_ttl' => new DateInterval('P1Y'),
],
'access_token_ttl' => new DateInterval('PT2H'),
'refresh_token_ttl' => new DateInterval('P2Y'),
'private_key' => resource_path('oauth-private.key'),
'public_key' => resource_path('oauth-public.key'),
];
```You need to run `./artisan oauth2:generate-keys` to create the oauth keys. You can optionally run `./artisan oauth2:seed` to run any seeds you may have defined for the oauth2 package.