-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuthInterface.php
175 lines (150 loc) · 5.1 KB
/
OAuthInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* Interface OAuthInterface
*
* @created 09.07.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
* @license MIT
*/
declare(strict_types=1);
namespace chillerlan\OAuth\Core;
use chillerlan\OAuth\Storage\OAuthStorageInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use Psr\Http\Message\{
RequestFactoryInterface, RequestInterface, ResponseInterface,
StreamFactoryInterface, StreamInterface, UriFactoryInterface, UriInterface
};
/**
* Specifies the basic methods for an OAuth provider.
*/
interface OAuthInterface extends ClientInterface{
/**
* A common user agent string that can be used in requests
*
* @var string
*/
public const USER_AGENT = 'chillerlanPhpOAuth/1.0.0 +https://github.com/chillerlan/php-oauth';
/**
* An identifier for the provider, usually the class name in ALLCAPS (required)
*
* @var string
*/
public const IDENTIFIER = '';
/**
* additional headers to use during authentication
*
* Note: must not contain: Accept-Encoding, Authorization, Content-Length, Content-Type
*
* @var array<string, string>
*/
public const HEADERS_AUTH = [];
/**
* additional headers to use during API access
*
* Note: must not contain: Authorization
*
* @var array<string, string>
*/
public const HEADERS_API = [];
/**
* Default scopes to apply if none were provided via the $scopes parameter
*
* @var string[]
*/
public const DEFAULT_SCOPES = [];
/**
* The delimiter string for scopes
*
* @var string
*/
public const SCOPES_DELIMITER = ' ';
/**
* Returns the name of the provider/class
*/
public function getName():string;
/**
* Returns the link to the provider's API docs, or null if the value is not set
*/
public function getApiDocURL():string|null;
/**
* Returns the link to the provider's credential registration/application page, or null if the value is not set
*/
public function getApplicationURL():string|null;
/**
* Returns the link to the page where a user can revoke access tokens, or null if the value is not set
*/
public function getUserRevokeURL():string|null;
/**
* Prepares the URL with optional $params which redirects to the provider's authorization prompt
* and returns a PSR-7 UriInterface with all necessary parameters set.
*
* If the provider supports RFC-9126 "Pushed Authorization Requests (PAR)", a request to the PAR endpoint
* shall be made within this method in order to send authorization data and obtain a temporary request URI.
*
* @link https://datatracker.ietf.org/doc/html/rfc5849#section-2.2
* @link https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
* @link https://datatracker.ietf.org/doc/html/rfc9126
* @see \chillerlan\OAuth\Core\PAR
*
* @param array<string, scalar>|null $params
* @param string[]|null $scopes
*/
public function getAuthorizationURL(array|null $params = null, array|null $scopes = null):UriInterface;
/**
* Authorizes the $request with the credentials from the given $token
* and returns a PSR-7 RequestInterface with all necessary headers and/or parameters set
*
* @see \chillerlan\OAuth\Core\OAuthProvider::sendRequest()
*/
public function getRequestAuthorization(RequestInterface $request, AccessToken|null $token = null):RequestInterface;
/**
* Prepares an API request to $path with the given parameters, gets authorization, fires the request
* and returns a PSR-7 ResponseInterface with the corresponding API response
*
* @param array<string, scalar|bool|null>|null $params
* @param StreamInterface|array<string, scalar|bool|null>|string|null $body
* @param array<string, string>|null $headers
*/
public function request(
string $path,
array|null $params = null,
string|null $method = null,
StreamInterface|array|string|null $body = null,
array|null $headers = null,
string|null $protocolVersion = null,
):ResponseInterface;
/**
* Sets an optional OAuthStorageInterface
*/
public function setStorage(OAuthStorageInterface $storage):static;
/**
* Returns the current OAuthStorageInterface
*/
public function getStorage():OAuthStorageInterface;
/**
* Sets an access token in the current OAuthStorageInterface (shorthand/convenience)
*/
public function storeAccessToken(AccessToken $token):static;
/**
* Gets an access token from the current OAuthStorageInterface (shorthand/convenience)
*/
public function getAccessTokenFromStorage():AccessToken;
/**
* Sets an optional PSR-3 LoggerInterface
*/
public function setLogger(LoggerInterface $logger):static;
/**
* Sets an optional PSR-17 RequestFactoryInterface
*/
public function setRequestFactory(RequestFactoryInterface $requestFactory):static;
/**
* Sets an optional PSR-17 StreamFactoryInterface
*/
public function setStreamFactory(StreamFactoryInterface $streamFactory):static;
/**
* Sets an optional PSR-17 UriFactoryInterface
*/
public function setUriFactory(UriFactoryInterface $uriFactory):static;
}