PHP OAuth2 Client for SteemConnect V2

in #utopian-io6 years ago (edited)

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

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @omeratagun, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Congratulations @hernandev, this post is the forth most rewarded post (based on pending payouts) in the last 12 hours written by a Dust account holder (accounts that hold between 0 and 0.01 Mega Vests). The total number of posts by Dust account holders during this period was 13503 and the total pending payments to posts in this category was $2360.28. To see the full list of highest paid posts across all accounts categories, click here.

If you do not wish to receive these messages in future, please reply stop to this comment.

Hey @hernandev I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

I like this @hernanadev. I really look forward to a steemphp api ,that would mean a hell lot to me.

It's on the plans!

Update: Just included unit tests covering 100% the code base.

https://i.imgur.com/kC7bwz7.png

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 64678.67
ETH 3086.68
USDT 1.00
SBD 3.87