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
- How to use Laravel Socialite?
https://laravel.com/docs/5.6/socialite - Ready to use providers
https://socialiteproviders.github.io/ - How to create Laravel Socialite friendly custom providers?
https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42
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
Posted on Utopian.io - Rewarding Open Source Contributors