friendship ended with social-app. php is my new best friend
1<?php
2/**
3 * Interface OAuthStorageInterface
4 *
5 * @created 09.07.2017
6 * @author Smiley <smiley@chillerlan.net>
7 * @copyright 2017 Smiley
8 * @license MIT
9 */
10declare(strict_types=1);
11
12namespace chillerlan\OAuth\Storage;
13
14use chillerlan\OAuth\Core\AccessToken;
15use Psr\Log\LoggerInterface;
16
17/**
18 * Specifies the methods required for an OAuth storage adapter
19 *
20 * The storage is intended to be invoked per-user, for whom it can
21 * store tokens, state etc. for any of the implemented providers.
22 *
23 * The implementer must ensure that the same storage instance is not used for multiple users.
24 */
25interface OAuthStorageInterface{
26
27 /*
28 * Common
29 */
30
31 /**
32 * Sets a logger. (LoggerAwareInterface is stupid)
33 */
34 public function setLogger(LoggerInterface $logger):static;
35
36 /**
37 * Prepares an AccessToken for storage (serialize, encrypt etc.)
38 * and returns a value that is suited for the underlying storage engine
39 *
40 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
41 */
42 public function toStorage(AccessToken $token):mixed;
43
44 /**
45 * Retrieves token JOSN from the underlying storage engine and returns an AccessToken
46 *
47 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
48 */
49 public function fromStorage(mixed $data):AccessToken;
50
51
52 /*
53 * Access token
54 */
55
56 /**
57 * Stores an AccessToken for the given $provider
58 *
59 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
60 */
61 public function storeAccessToken(AccessToken $token, string $provider):static;
62
63 /**
64 * Retrieves an AccessToken for the given $provider
65 *
66 * This method *must* throw a ItemNotFoundException if a token is not found
67 *
68 * @throws \chillerlan\OAuth\Storage\ItemNotFoundException
69 */
70 public function getAccessToken(string $provider):AccessToken;
71
72 /**
73 * Checks if a token for $provider exists
74 */
75 public function hasAccessToken(string $provider):bool;
76
77 /**
78 * Deletes the access token for a given $provider (and current user)
79 *
80 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
81 */
82 public function clearAccessToken(string $provider):static;
83
84 /**
85 * Deletes all access tokens (for the current user)
86 *
87 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
88 */
89 public function clearAllAccessTokens():static;
90
91
92 /*
93 * CSRF state
94 */
95
96 /**
97 * Stores a CSRF <state> value for the given $provider
98 *
99 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
100 */
101 public function storeCSRFState(string $state, string $provider):static;
102
103 /**
104 * Retrieves a CSRF <state> value for the given $provider
105 *
106 * This method *must* throw a ItemNotFoundException if a state is not found
107 *
108 * @throws \chillerlan\OAuth\Storage\ItemNotFoundException
109 */
110 public function getCSRFState(string $provider):string;
111
112 /**
113 * Checks if a CSRF state for the given provider exists
114 */
115 public function hasCSRFState(string $provider):bool;
116
117 /**
118 * Deletes a CSRF state for the given $provider (and current user)
119 *
120 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
121 */
122 public function clearCSRFState(string $provider):static;
123
124 /**
125 * Deletes all stored CSRF states (for the current user)
126 *
127 * @throws \chillerlan\OAuth\Storage\OAuthStorageException
128 */
129 public function clearAllCSRFStates():static;
130
131
132 /*
133 * PKCE verifier
134 */
135
136 /**
137 * Stores a PKCE verifier
138 */
139 public function storeCodeVerifier(string $verifier, string $provider):static;
140
141 /**
142 * Retrieves a PKCE verifier
143 *
144 * This method *must* throw a ItemNotFoundException if a verifier is not found
145 *
146 * @throws \chillerlan\OAuth\Storage\ItemNotFoundException
147 */
148 public function getCodeVerifier(string $provider):string;
149
150 /**
151 * Checks whether a PKCE verifier exists
152 */
153 public function hasCodeVerifier(string $provider):bool;
154
155 /**
156 * Deletes a PKCE verifier
157 */
158 public function clearCodeVerifier(string $provider):static;
159
160 /**
161 * Deletes all PKCE verifiers for this user
162 */
163 public function clearAllCodeVerifiers():static;
164
165}