oauth2-server/implementing-storage-classes.md

61 lines
2.6 KiB
Markdown
Raw Permalink Normal View History

2014-10-01 03:14:18 +05:30
---
layout: default
title: Installation
permalink: /implementing-storage-interfaces/
---
# Implementing the storage interfaces
2015-04-20 16:09:26 +05:30
In order to use both the resource server and authorization server you need to implement a number of interfaces.
2014-10-01 03:14:18 +05:30
If you are using the resource server you need to implement the following interfaces:
* `League\OAuth2\Server\Storage\SessionInterface` - contains methods for retrieving and setting sessions
* `League\OAuth2\Server\Storage\AccessTokenInterface` - contains methods for retrieving, creating and deleting access tokens
2015-07-27 17:38:53 +05:30
* `League\OAuth2\Server\Storage\ClientInterface` - single method to get a client
* `League\OAuth2\Server\Storage\ScopeInterface` - single method to get a scope
2014-10-01 03:14:18 +05:30
If you are using the authorization server you need to implement the following interfaces:
* `League\OAuth2\Server\Storage\SessionInterface` - contains methods for retrieving and setting sessions
* `League\OAuth2\Server\Storage\AccessTokenInterface` - contains methods for retrieving, creating and deleting access tokens
2015-07-27 17:38:53 +05:30
* `League\OAuth2\Server\Storage\ClientInterface` - single method to get a client
* `League\OAuth2\Server\Storage\ScopeInterface` - single method to get a scope
2014-10-01 03:14:18 +05:30
If you are using the authorization code grant you also need to implement:
* `League\OAuth2\Server\Storage\AuthCodeInterface` - contains methods for retrieving, creating and deleting authorization codes
If you are using the refresh token grant you also need to implement:
* `League\OAuth2\Server\Storage\RefreshTokenInterface` - contains methods for retrieving, creating and deleting refresh tokens
Once you have written your class implementations then inject them into the server like so:
~~~ php
// Resource server
$sessionStorage = new Storage\SessionStorage();
$accessTokenStorage = new Storage\AccessTokenStorage();
$clientStorage = new Storage\ClientStorage();
$scopeStorage = new Storage\ScopeStorage();
$server = new ResourceServer(
$sessionStorage,
$accessTokenStorage,
$clientStorage,
$scopeStorage
);
// Authorization server
$server->setSessionStorage(new Storage\SessionStorage);
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage);
$server->setClientStorage(new Storage\ClientStorage);
$server->setScopeStorage(new Storage\ScopeStorage);
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
~~~
If you are using a relational database you can find some example storage implementations in the `examples/relational` folder in the codebase.
2015-04-20 16:09:26 +05:30
You don't have to use a database to store all of your settings