Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.

Commit cb84c34

Browse files
committed
Merge branch 'feature/3-upstream-league-clients' into develop
Fixes #3 Conflicts: CHANGELOG.md
2 parents 5e33653 + bc5f4d1 commit cb84c34

14 files changed

+220
-178
lines changed

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 1.1.0 - TBD
5+
## 2.0.0 - 2019-11-12
66

77
### Added
88

9-
- Nothing.
9+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) adds support for all League OAuth2 Clients that inherits from the upstream `League\OAuth2\Client\Provider\AbstractProvider`.
10+
11+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) adds the method `forProviderKey(string $provider)` in `MissingProviderConfigException` in order to assert that the provider key has been set for providers in the configuration.
1012

1113
### Changed
1214

13-
- Nothing.
15+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) changes array disposition in the configuration files to include `provider` and `options` keys **(BC break)**. The provider array key tells the factory what to instantiate, and the options value is passed to the `Provider` constructor. Read the documentation on [local/environment-specific configuration](https://phly.github.io/phly-expressive-oauth2clientauthentication/config/) for specific implementation details and examples.
16+
17+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) allows the username to default to `$resourceOwner->getId()` in method `getUsernameFromResourceOwner(ResourceOwnerInterface $resourceOwner) : string` if methods `$resourceOwner->getEmail()` and `$resourceOwner->getNickname()` don't exist, instead of throwing an `UnexpectedResourceOwnerTypeException`.
1418

1519
### Deprecated
1620

1721
- Nothing.
1822

1923
### Removed
2024

21-
- Nothing.
25+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) removes `UnsupportedProviderException`, as it is not used anymore.
26+
27+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) removes `UnexpectedResourceOwnerTypeException`, as it is not used anymore.
2228

2329
### Fixed
2430

25-
- Nothing.
31+
- [#3](https://github.com/phly/phly-expressive-oauth2clientauthentication/pull/3) fixes a namespace reference within a shipped config file.
2632

2733
## 1.0.1 - TBD
2834

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55

66
This library provides a [league/oauth2-client](http://oauth2-client.thephpleague.com)
77
adapter for use with [zend-expressive-authentication](https://docs.zendframework.com/zend-expressive-authentication).
8-
It currently supports only the OAuth2 providers officially maintained by that
9-
project, including:
10-
11-
- Facebook
12-
- GitHub
13-
- Google
14-
- Instagram
15-
- LinkedIn
168

179
## Installation
1810

config/oauth2clientauthentication.global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @copyright Copyright (c) Matthew Weier O'Phinney
66
*/
77

8-
namespace Phly\OAuth2ClientAuthentication;
8+
namespace Phly\Expressive\OAuth2ClientAuthentication;
99

1010
return [
1111
'oauth2clientauthentication' => [

config/oauth2clientauthentication.local.php

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @copyright Copyright (c) Matthew Weier O'Phinney
66
*/
77

8-
namespace Phly\OAuth2ClientAuthentication;
8+
namespace Phly\Expressive\OAuth2ClientAuthentication;
99

1010
return [
1111
'oauth2clientauthentication' => [
@@ -14,60 +14,88 @@
1414
// Each OAuth2 provider has its own configuration. You may need to review
1515
// http://oauth2-client.thephpleague.com/providers/league/ for details
1616
// on each and what configuration options they accept.
17-
//
18-
// We do not currently support any third-party providers; if you wish to
19-
// do so, you will need to extend the `OAuth2ProviderFactory` to enable
20-
// them.
2117

2218
// Debug
2319
// This is the debug provider shipped within this component for purposes
2420
// of testing the OAuth2 client workflow within your applications.
2521
'debug' => [
26-
// Provide this if you have provided an alternate route path via
27-
// the oauth2clientauthentication.routes.debug key:
28-
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
22+
// Provider key must be present for factory creation.
23+
'provider' => Debug\DebugProvider::class,
24+
'options' => [
25+
// Provide this if you have provided an alternate route path via
26+
// the oauth2clientauthentication.routes.debug key:
27+
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
2928

30-
// Provide this if you want to use an alternate path for the OAuth2
31-
// "server" authorization:
32-
// 'authorization_url' => '/alternate/debug/authorization',
29+
// Provide this if you want to use an alternate path for the OAuth2
30+
// "server" authorization:
31+
// 'authorization_url' => '/alternate/debug/authorization',
32+
]
3333
],
3434

3535
// Facebook
3636
// 'facebook' => [
37-
// 'clientId' => '{facebook-app-id}',
38-
// 'clientSecret' => '{facebook-app-secret}',
39-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
40-
// 'graphApiVersion' => 'v2.10',
37+
// 'provider' => Provider\Facebook::class,
38+
// 'options' => [
39+
// 'clientId' => '{facebook-app-id}',
40+
// 'clientSecret' => '{facebook-app-secret}',
41+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
42+
// 'graphApiVersion' => 'v2.10',
43+
// ],
4144
// ],
4245

4346
// GitHub
4447
// 'github' => [
45-
// 'clientId' => '{github-client-id}',
46-
// 'clientSecret' => '{github-client-secret}',
47-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
48+
// 'provider' => Provider\Github::class,
49+
// 'options' => [
50+
// 'clientId' => '{github-client-id}',
51+
// 'clientSecret' => '{github-client-secret}',
52+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
53+
// ],
4854
// ],
4955

5056
// Google
5157
// 'google' => [
52-
// 'clientId' => '{google-client-id}',
53-
// 'clientSecret' => '{google-client-secret}',
54-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
55-
// 'hostedDomain' => '', // scheme + domain of your app
58+
// 'provider' => Provider\Google::class,
59+
// 'options' => [
60+
// 'clientId' => '{google-client-id}',
61+
// 'clientSecret' => '{google-client-secret}',
62+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
63+
// 'hostedDomain' => '', // scheme + domain of your app
64+
// ],
5665
// ],
5766

5867
// Instagram
5968
// 'instagram' => [
60-
// 'clientId' => '{instagram-client-id}',
61-
// 'clientSecret' => '{instagram-client-secret}',
62-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
63-
// 'host' => 'https://api.instagram.com', // Optional; this is the default
69+
// 'provider' => Provider\Instagram::class,
70+
// 'options' => [
71+
// 'clientId' => '{instagram-client-id}',
72+
// 'clientSecret' => '{instagram-client-secret}',
73+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
74+
// 'host' => 'https://api.instagram.com', // Optional; this is the default
75+
// ],
6476
// ],
6577

6678
// LinkedIn
6779
// 'linkedin' => [
68-
// 'clientId' => '{linkedin-client-id}',
69-
// 'clientSecret' => '{linkedin-client-secret}',
70-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
80+
// 'provider' => Provider\LinkedIn::class,
81+
// 'options' => [
82+
// 'clientId' => '{linkedin-client-id}',
83+
// 'clientSecret' => '{linkedin-client-secret}',
84+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
85+
// ],
86+
// ],
87+
88+
// Customized
89+
// 'custom' => [
90+
// 'provider' => Provider\GenericProvider::class,
91+
// 'options' => [
92+
// 'clientId' => '',
93+
// 'clientSecret' => '',
94+
// 'redirectUri' => '',
95+
// 'urlAuthorize' => '',
96+
// 'urlAccessToken' => '',
97+
// 'urlResourceOwnerDetails' => '',
98+
// ],
7199
// ],
72100
],
73101
'dependencies' => [

docs/book/config.md

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ return [
2323

2424
// Configure the production and debug routes for OAuth2 client callbacks
2525
// if desired. These strings will be relative to the 'auth_path' config
26-
// as specified above.
26+
// as specified above. Provider names in the regex should match the keys
27+
// associated with enabled providers in configuration. The "custom" string
28+
// is just an example of a provider key named "custom" described below.
2729
'routes' => [
2830
// Production path.
29-
// 'production' => '/{provider:facebook|github|google|instagram}|linkedin[/oauth2callback]',
31+
// 'production' => '/{provider:facebook|github|google|instagram|linkedin|custom}[/oauth2callback]',
3032

3133
// Debug path.
32-
// 'debug' => '/{provider:debug|facebook|github|google|instagram|linkedin}[/oauth2callback]',
34+
// 'debug' => '/{provider:debug|facebook|github|google|instagram|linkedin|custom}[/oauth2callback]',
3335
],
3436
],
3537
];
@@ -42,6 +44,9 @@ review the [league/oauth2-client providers documentation](http://oauth2-client.t
4244
for links to both full configuration documentation, as well as resources on how
4345
to obtain the various client identifiers and secrets you will need to use.
4446

47+
Each provider you define needs at least the provider key with the client class name and
48+
the options key with an array which is passed to the client constructor.
49+
4550
This information should _not_ be shipped directly in your repository, but rather
4651
included as part of your application environment.
4752

@@ -50,55 +55,87 @@ included as part of your application environment.
5055

5156
return [
5257
'oauth2clientauthentication' => [
53-
// Debug
54-
// This is the debug provider shipped within this component for purposes
55-
// of testing the OAuth2 client workflow within your applications.
5658
'debug' => [
57-
// Provide this if you have provided an alternate route path via
58-
// the oauth2clientauthentication.routes.debug key:
59-
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
60-
61-
// Provide this if you want to use an alternate path for the OAuth2
62-
// "server" authorization:
63-
// 'authorization_url' => '/alternate/debug/authorization',
59+
// Provider key must be present for factory creation.
60+
'provider' => Debug\DebugProvider::class,
61+
'options' => [
62+
// Provide this if you have provided an alternate route path via
63+
// the oauth2clientauthentication.routes.debug key:
64+
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
65+
66+
// Provide this if you want to use an alternate path for the OAuth2
67+
// "server" authorization:
68+
// 'authorization_url' => '/alternate/debug/authorization',
69+
]
6470
],
6571

6672
// Facebook
6773
// 'facebook' => [
68-
// 'clientId' => '{facebook-app-id}',
69-
// 'clientSecret' => '{facebook-app-secret}',
70-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
71-
// 'graphApiVersion' => 'v2.10',
74+
// 'provider' => Provider\Facebook::class,
75+
// 'options' => [
76+
// 'clientId' => '{facebook-app-id}',
77+
// 'clientSecret' => '{facebook-app-secret}',
78+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
79+
// 'graphApiVersion' => 'v2.10',
80+
// ],
7281
// ],
7382

7483
// GitHub
7584
// 'github' => [
76-
// 'clientId' => '{github-client-id}',
77-
// 'clientSecret' => '{github-client-secret}',
78-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
85+
// 'provider' => Provider\Github::class,
86+
// 'options' => [
87+
// 'clientId' => '{github-client-id}',
88+
// 'clientSecret' => '{github-client-secret}',
89+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
90+
// ],
7991
// ],
8092

8193
// Google
8294
// 'google' => [
83-
// 'clientId' => '{google-client-id}',
84-
// 'clientSecret' => '{google-client-secret}',
85-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
86-
// 'hostedDomain' => '', // scheme + domain of your app
95+
// 'provider' => Provider\Google::class,
96+
// 'options' => [
97+
// 'clientId' => '{google-client-id}',
98+
// 'clientSecret' => '{google-client-secret}',
99+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
100+
// 'hostedDomain' => '', // scheme + domain of your app
101+
// ],
87102
// ],
88103

89104
// Instagram
90105
// 'instagram' => [
91-
// 'clientId' => '{instagram-client-id}',
92-
// 'clientSecret' => '{instagram-client-secret}',
93-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
94-
// 'host' => 'https://api.instagram.com', // Optional; this is the default
106+
// 'provider' => Provider\Instagram::class,
107+
// 'options' => [
108+
// 'clientId' => '{instagram-client-id}',
109+
// 'clientSecret' => '{instagram-client-secret}',
110+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
111+
// 'host' => 'https://api.instagram.com', // Optional; this is the default
112+
// ],
95113
// ],
96114

97115
// LinkedIn
98116
// 'linkedin' => [
99-
// 'clientId' => '{linkedin-client-id}',
100-
// 'clientSecret' => '{linkedin-client-secret}',
101-
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
117+
// 'provider' => Provider\LinkedIn::class,
118+
// 'options' => [
119+
// 'clientId' => '{linkedin-client-id}',
120+
// 'clientSecret' => '{linkedin-client-secret}',
121+
// 'redirectUri' => '', // based on the auth_path + production route; must be fully qualifed
122+
// ],
123+
// ],
124+
125+
// Customized
126+
// It's possible to configure any provider that extend the League AbstractProvider, including custom
127+
// implementations or extensions. This example uses GenericProvider which can be used with any OAuth
128+
// 2.0 Server that uses Bearer tokens.
129+
// 'custom' => [
130+
// 'provider' => Provider\GenericProvider::class,
131+
// 'options' => [
132+
// 'clientId' => '',
133+
// 'clientSecret' => '',
134+
// 'redirectUri' => '',
135+
// 'urlAuthorize' => '',
136+
// 'urlAccessToken' => '',
137+
// 'urlResourceOwnerDetails' => '',
138+
// ],
102139
// ],
103140
],
104141
'dependencies' => [

docs/book/debug.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ when that occurs, the debug provider is added to the list of allowed providers,
1313
and its authorization handler is mapped to a route.
1414

1515
You can configure both the authorization URI as well as the template for the
16-
callback URI:
16+
callback URI in the options array:
1717

1818
```php
1919
// e.g. config/autoload/oauth2-client.local.php:
2020

2121
return [
2222
'oauth2clientauthentication' => [
2323
'debug' => [
24-
// Provide this if you have provided an alternate route path via
25-
// the oauth2clientauthentication.routes.debug key:
26-
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
24+
'provider' => Debug\DebugProvider::class,
25+
'options' => [
26+
// Provide this if you have provided an alternate route path via
27+
// the oauth2clientauthentication.routes.debug key:
28+
// 'callback_uri_template' => '/alternate/debug/callback?code=%s&state=%s',
2729

28-
// Provide this if you want to use an alternate path for the OAuth2
29-
// "server" authorization:
30-
// 'authorization_url' => '/alternate/debug/authorization',
30+
// Provide this if you want to use an alternate path for the OAuth2
31+
// "server" authorization:
32+
// 'authorization_url' => '/alternate/debug/authorization',
33+
]
3134
],
3235
],
3336
];

docs/book/intro.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22

33
This library provides a [league/oauth2-client](http://oauth2-client.thephpleague.com)
44
adapter for use with [zend-expressive-authentication](https://docs.zendframework.com/zend-expressive-authentication).
5-
It currently supports only the OAuth2 providers officially maintained by that
6-
project, including:
7-
8-
- Facebook
9-
- GitHub
10-
- Google
11-
- Instagram
12-
- LinkedIn
5+
It supports all OAuth2 Clients that inherit from `League\OAuth2\Client\Provider\AbstractProvider`.
136

147
## Installation
158

src/Exception/MissingProviderConfigException.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ public static function forProvider(string $provider) : self
2020
$provider
2121
));
2222
}
23+
24+
public static function forProviderKey(string $provider) : self
25+
{
26+
return new self(sprintf(
27+
'No provider key found for OAuth2 provider "%s"; please provide it via '
28+
. 'the config key oauth2clientauthentication.%s.provider',
29+
$provider,
30+
$provider
31+
));
32+
}
2333
}

0 commit comments

Comments
 (0)