Advanced customizations
Extending base methods
Many of the behaviors of your Oauth2Client plugin are provided by a base class,
Oauth2ClientPluginBase
, and can be customized by overriding or extending
methods from that class. In addition the collaborators
attribute allows you to override helper classes used to build your
GenericClient
.
Extension points in GenericClient
The league/oauth2-client
library uses the name Provider for classes that
provide Oauth2 token management. This naming is reflected in our
::getProvider
method in Oauth2ClientPluginInterface
The implementation in
Oauth2ClientPluginInterface
creates a new instance
of \League\OAuth2\Client\Provider\GenericProvider
which provides several
methods that can be used to customize your client:
::setHttpClient(client: ClientInterface)
allows you to customize the GuzzleHttpClient
.setOptionProvider(provider: OptionProviderInterface)
allows you to customize the options sent to the HttpClient created for you byGenericProvider
.
Using a dedicated provider
The only requirement on the ::getProvider
method in Oauth2ClientPluginInterface
is that you return an AbstractProvider
instance. This allows you to either
create your own class that implements AbstractProvider
to to require one
of the many composer packages that implement this abstract class for various
services. You can then instantiate and return an instance of your custom or
third-party provider in your implementation of ::getProvider
.
The maintainers support a small number
of these and provide an index of other packages.
Examples of such dedicated providers include:
- Amazon
- Azure
- Dropbox
- GitHub