Skip to content

`detain/db_abstraction` (mysqli,PDO,etc) Storage for `thephpleague/oauth2-server`

License

Notifications You must be signed in to change notification settings

detain/oauth2-server-mydb-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MyDb\Generic Repository for thephpleague oauth2 server

Travis branch Codecov Software License

This is an Implentation of the thephpleague/oauth2-server storage interfaces for MyDb\Generic Repository.

Usage

use Detain\OAuth2\Server\Repository\MyDb\AccessTokenRepository;
use Detain\OAuth2\Server\Repository\MyDb\ClientRepository;
use Detain\OAuth2\Server\Repository\MyDb\ScopeRepository;
use Detain\OAuth2\Server\Repository\MyDb\SessionsRepository;
use Detain\OAuth2\Server\Repository\MyDb\AuthCodeRepository;
use Detain\OAuth2\Server\Repository\MyDb\RefreshTokenRepository;
use League\OAuth2\Server\ResourceServer;
use MyDb\Mysqli\Db;

$db = new Db();

$sessionRepository = new SessionRepository($db);
$accessTokenRepository = new AccessTokenRepository($db);
$clientRepository = new ClientRepository($db);
$scopeRepository = new ScopeRepository($db);

$server = new ResourceServer($sessionRepository, $accessTokenRepository, $clientRepository, $scopeRepository);

Once you have an instance of League\OAuth2\Server\AuthorizationServer you can set the different storages.

use Detain\OAuth2\Server\Repository\MyDb\AccessTokenRepository;
use Detain\OAuth2\Server\Repository\MyDb\ClientRepository;
use Detain\OAuth2\Server\Repository\MyDb\ScopeRepository;
use Detain\OAuth2\Server\Repository\MyDb\SessionsRepository;
use Detain\OAuth2\Server\Repository\MyDb\AuthCodeRepository;
use Detain\OAuth2\Server\Repository\MyDb\RefreshTokenRepository;

$server->setAccessTokenRepository(new AccessTokenRepository($db));
$server->setClientRepository(new ClientRepository($db));
$server->setScopeRepository(new ScopeRepository($db));
$server->setSessionRepository(new SessionRepository($db));
$server->setAuthCodeRepository(new AuthCodeRepository($db));
$server->setRefreshTokenRepository(new RefreshTokenRepositoryRepository($db));

Installation

The recommended installation method is via Composer.

In your project root just run:

$ composer require detain/oauth2-server-mydb-storage

Testing the client credentials grant example

Send the following cURL request:

curl -X "POST" "https://mynew.interserver.net/oauth/server/client_credentials.php/access_token" \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-H "Accept: 1.0" \
	--data-urlencode "grant_type=client_credentials" \
	--data-urlencode "client_id=rocketchat_2773" \
	--data-urlencode "client_secret=s3cr3t" \
	--data-urlencode "scope=basic email"

Testing the password grant example

Send the following cURL request:

curl -X "POST" "https://mynew.interserver.net/oauth/server/password.php/access_token" \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-H "Accept: 1.0" \
	--data-urlencode "grant_type=password" \
	--data-urlencode "client_id=rocketchat_2773" \
	--data-urlencode "client_secret=s3cr3t" \
	--data-urlencode "username=alex" \
	--data-urlencode "password=whisky" \
	--data-urlencode "scope=basic email"

Testing the refresh token grant example

Send the following cURL request. Replace {{REFRESH_TOKEN}} with a refresh token from another grant above:

curl -X "POST" "https://mynew.interserver.net/oauth/server/refresh_token.php/access_token" \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-H "Accept: 1.0" \
	--data-urlencode "grant_type=refresh_token" \
	--data-urlencode "client_id=rocketchat_2773" \
	--data-urlencode "client_secret=s3cr3t" \
	--data-urlencode "refresh_token={{REFRESH_TOKEN}}"

About

`detain/db_abstraction` (mysqli,PDO,etc) Storage for `thephpleague/oauth2-server`

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages