Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 56090fd

Browse files
committed
:octocat:
1 parent a13ea26 commit 56090fd

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,37 @@
2626
# Documentation
2727
## Requirements
2828
- PHP 7.2+
29-
- the [Sodium](http://php.net/manual/book.sodium.php) extension for token encryption
3029
- a [PSR-18](https://www.php-fig.org/psr/psr-18/) compatible HTTP client library of your choice
30+
- optional [PSR-17](https://www.php-fig.org/psr/psr-17/) compatible Request-, Response- and UriFactories
3131
- see [`chillerlan/php-oauth`](https://github.com/chillerlan/php-oauth) for already implemented providers
3232

3333
## Getting Started
34-
In order to instance an [`OAuthInterface`](https://github.com/chillerlan/php-oauth-core/blob/master/src/Core/OAuthInterface.php) you you'll need to invoke a [`HTTPClientInterface`](https://github.com/chillerlan/php-httpinterface/blob/master/src/HTTPClientInterface.php), [`OAuthStorageInterface`](https://github.com/chillerlan/php-oauth-core/blob/master/src/Storage/OAuthStorageInterface.php) and `OAuthOptions` (a [`ContainerInterface`](https://github.com/chillerlan/php-traits/blob/master/src/ContainerInterface.php)) objects first:
34+
In order to instance an [`OAuthInterface`](https://github.com/chillerlan/php-oauth-core/blob/master/src/Core/OAuthInterface.php) you you'll need to invoke a PSR-18 [`ClientInterface`](https://github.com/php-fig/http-client/blob/master/src/ClientInterface.php), a [`OAuthStorageInterface`](https://github.com/chillerlan/php-oauth-core/blob/master/src/Storage/OAuthStorageInterface.php) and `OAuthOptions` (a [`SettingsContainerInterface`](https://github.com/chillerlan/php-settings-container/blob/master/src/SettingsContainerInterface.php)) objects first:
3535
```php
3636
use chillerlan\OAuth\Providers\<PROVIDER_NAMESPACE>\<PROVIDER>;
3737
use chillerlan\OAuth\{OAuthOptions, Storage\SessionTokenStorage};
38-
use chillerlan\HTTP\Psr18\CurlClient;
38+
use <PSR-18 HTTP Client>;
3939

4040
// OAuthOptions
4141
$options = new OAuthOptions([
4242
// OAuthOptions
4343
'key' => '<API_KEY>',
4444
'secret' => '<API_SECRET>',
4545
'callbackURL' => '<API_CALLBACK_URL>',
46-
47-
// HTTPOptions
48-
'ca_info' => '/path/to/cacert.pem', // https://curl.haxx.se/ca/cacert.pem
49-
'userAgent' => 'my-awesome-oauth-app',
5046
]);
5147

52-
// HTTPClientInterface
53-
$http = new CurlClient($options);
48+
// a \Psr\Http\Client\ClientInterface
49+
$http = new HttpClient;
5450

5551
// OAuthStorageInterface
5652
// a persistent storage is required for authentication!
5753
$storage = new SessionTokenStorage($options);
5854

59-
// optional scopes for OAuth2 providers
60-
$scopes = [
61-
Provider::SCOPE_WHATEVER,
62-
];
63-
6455
// an optional \Psr\LoggerInterface logger
6556
$logger = new Logger;
6657

6758
// invoke and use the OAuthInterface
68-
$provider = new Provider($http, $storage, $options, $logger, $scopes);
59+
$provider = new Provider($http, $storage, $options, $logger);
6960
```
7061

7162
## Authentication
@@ -79,10 +70,15 @@ echo '<a href="?login='.$provider->serviceName.'">connect with '.$provider->serv
7970
```
8071

8172
### Step 2: redirect to the provider
82-
Redirect to the provider's login screen with optional arguments in the authentication URL, like permissions etc.
73+
Redirect to the provider's login screen with optional arguments in the authentication URL, like permissions, scopes etc.
8374
```php
75+
// optional scopes for OAuth2 providers
76+
$scopes = [
77+
Provider::SCOPE_WHATEVER,
78+
];
79+
8480
if(isset($_GET['login']) && $_GET['login'] === $provider->serviceName){
85-
header('Location: '.$provider->getAuthURL(['extra-param' => 'val']));
81+
header('Location: '.$provider->getAuthURL(['extra-param' => 'val'], $scopes));
8682
}
8783
```
8884

@@ -145,7 +141,7 @@ In order to use a provider or storage, that is not yet supported, you'll need to
145141
The OAuth1 implementation is close to Twitter's specs and *should* work for most other OAuth1 services.
146142

147143
```php
148-
use chillerlan\OAuth\Providers\OAuth1Provider;
144+
use chillerlan\OAuth\Core\OAuth1Provider;
149145

150146
class MyOauth1Provider extends Oauth1Provider{
151147

@@ -160,7 +156,7 @@ class MyOauth1Provider extends Oauth1Provider{
160156
### [`OAuth2Interface`](https://github.com/chillerlan/php-oauth/tree/master/src/Providers/OAuth2Provider.php)
161157
[OAuth2 is a very straightforward... mess](https://hueniverse.com/oauth-2-0-and-the-road-to-hell-8eec45921529). Please refer to your provider's docs for implementation details.
162158
```php
163-
use chillerlan\OAuth\Providers\OAuth2Provider;
159+
use chillerlan\OAuth\Core\OAuth2Provider;
164160

165161
class MyOauth2Provider extends Oauth2Provider implements ClientCredentials, CSRFToken, TokenExpires, TokenRefresh{
166162
use OAuth2ClientCredentialsTrait, OAuth2CSRFTokenTrait, OAuth2TokenRefreshTrait;

0 commit comments

Comments
 (0)