joomla / oauth1
Joomla OAuth1 Package
Fund package maintenance!
joomla
community.joomla.org/sponsorship-campaigns.html
Installs: 208 610
Dependents: 3
Suggesters: 0
Security: 0
Stars: 4
Watchers: 17
Forks: 6
Open Issues: 2
Type:joomla-package
Requires
- php: ^8.1.0
- joomla/application: ^3.0
- joomla/http: ^3.0
- joomla/input: ^3.0
- joomla/registry: ^3.0
- joomla/session: ^3.0
- joomla/uri: ^3.0
Requires (Dev)
- joomla/event: ^3.0
- joomla/test: ^3.0
- phan/phan: ^5.4.2
- phpstan/phpstan: ^1.10.7
- phpunit/phpunit: ^9.5.28
- squizlabs/php_codesniffer: ^3.7.2
This package is auto-updated.
Last update: 2024-12-08 21:31:50 UTC
README
Using the OAuth1 Package
The OAuth1 package supports OAuth 1.0 and 1.0a protocol versions. The client facilitates authorised RESTful HTTP requests. You can find the OAuth RFC at http://tools.ietf.org/html/rfc5849.
The Client is abstract, it must be extended and have the two abstract methods implemented. These methods are verifyCredentials and validateResponse:
- verifyCredentials is used to check if an existing access token is still valid. Servers may have different ways of testing the access token validity, for example Twitter has a specific URL for this. There are several reasons an access token may be invalid: the token expires after some time, the user changes his password which invalidates the access token, the user de-authorizes your app, the user logs out.
- validateResponse method is used to check the response codes. This method abstract because servers may have different response error bodies.
By default the client will act as an OAuth 1.0a client. If you need an OAuth 1.0 client, than you have to set the constructor $version parameter to '1.0'. The client requires additional options and this can be done by injecting in a Registry object:
use Joomla\Oauth1\Client; use Joomla\Registry\Registry; $options = new Registry; $options->set('consumer_key', $key); $options->set('consumer_secret', $secret); $options->set('callback', $my_url); $options->set('accessTokenURL', $accessToken); $options->set('authenticateURL', $authenticate); $options->set('authoriseURL', $authorise); $options->set('requestTokenURL', $requestToken); // Call the Client constructor. parent::__construct($this->options);
By default you have to set and send headers manually in your application, but if you want this to be done automatically by the client you can set Registry option 'sendheaders' to true.
$options->set('sendheaders', true);
Now you can authenticate the user and request him to authorise your application in order to get an access token, but if you already have an access token stored you can set it and if it's still valid your application will use it.
// Set the stored access token. $oauth->setToken($token); $access_token = $oauth->authenticate();
When calling the authenticate() method, your stored access token will be used only if it's valid, a new one will be created if you don't have an access token or if the stored one is not valid. The method will return a valid access token that's going to be used.
Now you can perform authorised requests using the oauthRequest method.
A More Complete Example
See the Twitter and LinkedIn packages for examples demonstrating more about the OAuth1 package.
TODO: add links to the Twitter and LinkedIn packages after this packages are merged.
More Information
The following resources contain more information:
- [http://api.joomla.org/](Joomla! API Reference)
- [http://tools.ietf.org/html/rfc5849](OAuth RFC)
Installation via Composer
Add "joomla/oauth1": "~3.0"
to the require block in your composer.json and then run composer install
.
{ "require": { "joomla/oauth1": "~3.0" } }
Alternatively, you can simply run the following from the command line:
composer require joomla/oauth1 "~3.0"