This project allows an easy and smooth integration of SteemConnect V2 OAuth 2 flow into PHP applications.
This is the first installment, of a bigger library being built (SteemConnect V2 SDK for PHP), where this client will handle the Authorization flow.
Even being part of a larger project, it can be easily used standalone to handle SteemConnect authorization using PHP.
Nothing better for developers than showing the actual code:
composer require hernandev/oauth2-sc2
// aliasing classes.
use SteemConnect\OAuth2\Config\Config;
use SteemConnect\OAuth2\Provider\Provider;
// start a configuration object, passing SC2 application ID & secret:
$config = new Config('your.app', 'your-long-secret-id-here-keep-it-secret');
// define which OAuth scopes you need users to authorize:
$config->setScopes([
'login', 'vote', 'comment', 'comment_delete'
]);
// set the return/callback URL, so SteemConnect will redirect
// users back to your application.
$config->setReturnUrl('https://my-steem-app-is-awesome.com/login/return');
// create an OAuth provider instance, passing
// the configuration justs created:
$provider = new Provider($config);
// get the URL string that you will redirect to
// (you may use a freamework redirect or a header() call):
$provider->getAuthorizationUrl();
// just calling the parseReturn on the provider, will
// automatically exchange the access code by the actual access token:
$token = $provider->parseReturn();
// gets the actual token that will be used on requests.
$token->getToken();
// gets the expiration date, so you know the token
// is no longer valid.
$token->getExpires();
// gets the refresh token, which may be used to issue a new token,
// after the original one expired.
$token->getRefreshToken();
// gets the standard ID for the account athorizing your app,
// it means, this field retrieves the account @username.
$token->getResourceOwnerId();
// gets the resource owner instance.
$owner = $provider->getResourceOwner($token);
// now you can use any key you may
// see on steemd.com directly on that $owner object!!!
$owner->profile_json;
$owner->balance;
$owner->reputation;
// ....
Fully Object Oriented PHP, requirig at least PHP 7.1+ (no legacy versions).
Built on top of League's OAuth Client.
This project will be the base for a PHP SDK for SteemConnect V2, so most new features will be done on the new repository.
For this project, both manual and automated tests are more than welcome.
My discord username is hernandev#5834, and just hernandev on almost any other social platform.