Skip to content

Commit 6af4392

Browse files
add OAuthServiceInterface.php
1 parent e1eb4f4 commit 6af4392

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,70 @@ $accessToken = $google->getAccessToken($code);
152152
$user = $google->getUser($accessToken);
153153
```
154154

155+
## OAuthServiceInterface
156+
157+
158+
159+
The `OAuthServiceInterface` is an interface that defines the contract for an OAuth service. It provides methods for retrieving configuration, authorization URL, access token, and user data from an OAuth service.
160+
161+
### Usage
162+
163+
To use this interface, you need to create a class that implements it and provides the necessary functionality. Here's an example of how you can implement the `OAuthServiceInterface`:
164+
165+
```php
166+
<?php
167+
168+
namespace Effectra\ThirdParty;
169+
170+
class MyOAuthService implements OAuthServiceInterface
171+
{
172+
// Implement the getConfig() method
173+
public function getConfig(): array
174+
{
175+
// Return the configuration array for the OAuth service
176+
}
177+
178+
// Implement the getAuthURL() method
179+
public function getAuthURL(): string
180+
{
181+
// Return the authorization URL for the OAuth service
182+
}
183+
184+
// Implement the getAccessToken() method
185+
public function getAccessToken(string $code): string
186+
{
187+
// Get the access token for the OAuth service using the authorization code
188+
}
189+
190+
// Implement the getUser() method
191+
public function getUser(string $token): ?array
192+
{
193+
// Get the user data from the OAuth service using the access token
194+
}
195+
}
196+
```
197+
198+
In the above example, you need to replace the placeholder methods with your actual implementation based on the OAuth service you are integrating with.
199+
200+
### Method Overview
201+
202+
#### `getConfig(): array`
203+
204+
This method returns the configuration array for the OAuth service.
205+
206+
#### `getAuthURL(): string`
207+
208+
This method returns the authorization URL for the OAuth service.
209+
210+
#### `getAccessToken(string $code): string`
211+
212+
This method retrieves the access token for the OAuth service using the authorization code provided as a parameter.
213+
214+
#### `getUser(string $token): ?array`
215+
216+
This method retrieves the user data from the OAuth service using the access token provided as a parameter. It returns an array containing user data or `null` if the operation is unsuccessful.
217+
218+
155219
## License
156220

157221
This library is open source and available under the [MIT License](LICENSE).

src/OAuthServiceInterface.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Effectra\ThirdParty;
4+
5+
/**
6+
* Interface OAuthServiceInterface
7+
*
8+
* This interface defines the contract for an OAuth service.
9+
*/
10+
interface OAuthServiceInterface extends OAuthConfig
11+
{
12+
/**
13+
* Get the configuration array for the OAuth service.
14+
*
15+
* @return array The configuration array.
16+
*/
17+
public function getConfig(): array;
18+
19+
/**
20+
* Get the authorization URL for the OAuth service.
21+
*
22+
* @return string The authorization URL.
23+
*/
24+
public function getAuthURL(): string;
25+
26+
/**
27+
* Get the access token for the OAuth service using the authorization code.
28+
*
29+
* @param string $code The authorization code.
30+
* @return string The access token.
31+
*/
32+
public function getAccessToken(string $code): string;
33+
34+
/**
35+
* Get the user data from the OAuth service using the access token.
36+
*
37+
* @param string $token The access token.
38+
* @return array|null The user data array or null if unsuccessful.
39+
*/
40+
public function getUser(string $token): ?array;
41+
}

0 commit comments

Comments
 (0)