Steem OAuth2 Provider for Laravel Socialite

in #utopian-io6 years ago (edited)

I like Steem and many other blockchains. As a developer, I always like to take the advantage of using ready to use libraries. As a PHP developer, I always like to use Laravel and it's rich contribution background.

Original image: laravel.com/assets/img/components/logo-socialite.svg

I decided to make an application over Steemit. So I needed Laravel Socialite for authentication. But until today, it did not have Steem Provider. So I did. It has Steem Provider in the repository, but not listed here, yet.

https://github.com/SocialiteProviders/Providers/tree/master/src/Steem

Toolbox

Work Description

  • Creating a custom provider for Steem Connect v2
  • Following StyleCI rules

https://github.com/SocialiteProviders/Providers/pull/144

P.S. No contribution needed

How to use?

Please follow Socialite Providers page. Whenever it's listed by the team, you can reach the introductions.

I assume that, they have added it on to Packagist as socialiteproviders/steem

It's available on Packagist now! So, here is composer command:

composer require socialiteproviders/steem

LoginController.php

/**
     * Redirect the user to the Steem Connect authentication page.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('steem')->redirect();
    }

/**
     * Obtain the user information from Steem Connect
     *
     * @return \Illuminate\Http\Response
     */
    public function handleProviderCallback()
    {
        $user = Socialite::driver('steem')->user();

        // If the user already registered, update access token.
        // If no matching user exists, create one.
        $auth = User::updateOrCreate(
            [
                'account'       => $user->nickname
            ],
            [
                'name'          => $user->name,
                'account'       => $user->nickname,
                'profile_image' => $user->avatar,
                'access_token'  => $user->token,
            ]
        );

        auth()->login($auth);
        return redirect()->to('/home');
    }

Note: auth()->login($auth); requires matching User Model!

Enjoy,
Burak

Proof of work

Capture.PNG

POW.png



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

Would have been better to use their repo on this post, see if you can modify it.

So you could have linked the proper pull request that was merged

I would have loved to see how it looks like when implemented in a Laravel project.

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

Hey @helo, 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!

Hey!

I will share a Laravel project, if I can complete to implement it. By the way, Service Providers page has a different repo as GitHub Pages. And they are sharing on Packagist for Composer with their namespace. So unfortunately, nothing to do in my side. But as you know, they accepted my pull request. I will update this post whenever they publish / update their repositories.

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

Achievements

  • WOW WOW WOW People loved what you did here. GREAT JOB!
  • 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

1UP-Kayrex_tiny.png

You've got upvoted by Utopian-1UP!

You can give up to ten 1UP's to Utopian posts every day after they are accepted by a Utopian moderator and before they are upvoted by the official @utopian-io account. Install the @steem-plus browser extension to use 1UP. By following the 1UP-trail using SteemAuto you support great Utopian authors and earn high curation rewards at the same time.


1UP is neither organized nor endorsed by Utopian.io!

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 63793.25
ETH 3410.80
USDT 1.00
SBD 2.59