mathieutu / lvconnect-socialite
LVConnect OAuth2 Provider for Laravel Socialite
Requires
- php: >= 7.1
- ext-json: *
- illuminate/console: ~5.7|^6.0|^7.0
- socialiteproviders/manager: ^3.3
This package is auto-updated.
Last update: 2024-10-29 05:22:25 UTC
README
Abstract
LVConnect is a project that aims to unify login over all Linkvalue apps with an authentication service based on OAuth2.
Linkvalue is a french web/mobile agency.
Socialite is a simple and convenient way to authenticate users with OAuth providers for Laravel.
This package is an internal tool. You can download it and use it as an example for making your own, but it will be unusable if you're not a Linkvalue partner.
Installation
This assumes that you have composer installed globally
composer require mathieutu/lvconnect-socialite
Configuration setup
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command artisan config:cache
) all config is still available.
Add to config/services.php
.
'lvconnect' => [ 'client_id' => env('LVCONNECT_ID'), 'client_secret' => env('LVCONNECT_SECRET'), 'redirect' => env('LVCONNECT_CALLBACK'), ],
If you want to do some test with another url that production one, you can optionally add an url key with the base url:
'url' => 'https://lvconnect-staging.herokuapp.com',
Fill your .env
/ environment variables:
Create your application in the LVConnect website and fill the information in your env:
LVCONNECT_ID=XXXX LVCONNECT_SECRET=XXXX LVCONNECT_CALLBACK=http://my-full-website-url.localhost/login/callback
Usage
See Laravel docs on socialite usage.
- You should now be able to use it like you would regularly use Socialite.
return $socialite->driver('lvconnect')->redirect();
You can publish all the auth scaffolding with the following command:
php artisan lvconnect:publish
Stateless
You can set whether or not you want to use the provider as stateless. LVConnect supports whatever option you choose.
Note: If you are using this with Lumen, all providers will automatically be stateless since Lumen does not keep track of state.
// to turn off stateless return Socialite::with('lvconnect')->stateless(false)->redirect(); // to use stateless return Socialite::with('lvconnect')->stateless()->redirect();
The LVConnect User.
The user that socialite will provide has this shape:
User {#341 ▼
+accessTokenResponseBody: array:6 [▼
"access_token" => "0bc47e47-1e88-4d08-a402-1cd7c235de3d"
"token_type" => "bearer"
"expires_in" => 172800
"refresh_token" => "73a17012-b999-4300-8d4d-99e8675abc08"
"scope" => array:3 [▼
0 => "users:get"
1 => "users:modify"
2 => "profile:get"
]
"need_password_change" => false
]
+token: "0bc47e47-1e88-4d08-a402-1cd7c235de3d"
+refreshToken: "73a17012-b999-4300-8d4d-99e8675abc08"
+expiresIn: 172800
+id: "589ae9cfe2eb1d0009790659"
+nickname: null
+name: "Foo BAR"
+email: "foo.bar@link-value.fr"
+avatar: "https://www.gravatar.com/avatar/d5763d35fe855464633ff3ec5064ecad?s=200"
+user: array:10 [▼
"tags" => []
"roles" => array:5 [▼
0 => "tech"
1 => "business"
2 => "hr"
3 => "board"
4 => "com"
]
"firstName" => "Foo"
"lastName" => "BAR"
"email" => "foo.bar@link-value.fr"
"createdAt" => "2017-02-08T09:50:07.813Z"
"city" => "Lyon"
"description" => "A really good friend!"
"profilePictureUrl" => "https://www.gravatar.com/avatar/d5763d35fe855464633ff3ec5064ecad?s=200"
"id" => "589ae9cfe2eb1d0009790659"
]
}
It's a instance of \Laravel\Socialite\Two\User class.
Reference
License
This LVConnect Socialite package is an open-sourced software licensed under the MIT license.
Contributing
Issues and PRs are obviously welcomed and encouraged, for features as well as documentation.