PHP OAuth2 Client for SteemConnect V2

Words
183
Reading
1 min
Listen
Play
9y

New Projects

  • What is the project about?

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.

  • How does it work?

Nothing better for developers than showing the actual code:

  • Installation:
composer require hernandev/oauth2-sc2
  • Usage - Asking for Authorization:
// 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();

  • Usage - Parsing the Return:
// just calling the parseReturn on the provider, will 
// automatically exchange the access code by the actual access token: 
$token = $provider->parseReturn();
  • With the user token in hands:
// 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();

  • ResourceOwner Interface
// 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;
// ....
  • Technology Stack

Fully Object Oriented PHP, requirig at least PHP 7.1+ (no legacy versions).

Built on top of League's OAuth Client.

  • Roadmap

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.

  • How to contribute?

My discord username is hernandev#5834, and just hernandev on almost any other social platform.



Posted on Utopian.io - Rewarding Open Source Contributors

PHP OAuth2 Client for SteemConnect V2 | Ecency