33
44Add registration and log in to you application via third party identity providers (e.g. Gitlab, Facebook, ...).
55
6- The package is compatible with the [ Laravel Socialite] ( https://laravel.com/docs/8.x/socialite ) providers
7- as well as the community driven [ Socialite Providers] ( https://socialiteproviders.com/ ) website.
6+ While the package provides controllers, models, migrations and routes to handle registration and login actions
7+ it does not dictate how the user interface should look and how to validate users' data. It does however
8+ provide a starting point that you can customize based on your needs.
89
9- > Requires ** Laravel >= 7.20** and ** PHP >= 7.2**
10+ The package is compatible with [ Laravel Socialite] ( https://laravel.com/docs/socialite ) providers
11+ as well as the community driven [ Socialite Providers] ( https://socialiteproviders.com/ ) .
12+
13+ ** features**
14+
15+ - Handle user registration via third party providers;
16+ - Handle user log in via third party providers;
17+ - Customizable controllers, migration and models that will live in your application namespace;
18+ - Save identity and token inside the database, using
19+ [ encryption and pseudoanonimization] ( #how-data-is-stored-in-the-database ) ;
20+ - Provide login/register button as Blade component;
21+ - Support all [ Laravel Socialite] ( https://laravel.com/docs/socialite )
22+ and [ Socialite Providers] ( https://socialiteproviders.com/ ) ;
23+ - Add custom providers.
24+
25+ ** requirements**
26+
27+ ` oneofftech/laravel-connect-identity ` requires ** Laravel >= 7.20** and ** PHP >= 7.2** .
1028
1129> ** The package is currently a Work In Progress.** The api might change without notice so it is not yet
1230 suitable for production environments.
1331
14- ## Installation
32+ ## Getting started
33+
34+ ### Installation
1535
1636You can install this package via Composer by running this command in your terminal in the root of your project:
1737
@@ -20,17 +40,21 @@ composer require oneofftech/laravel-connect-identity
2040```
2141
2242> The service provider ` Oneofftech\Identities\IdentitiesServiceProvider::class `
23- > is automatically registered as part of the Laravel service discovery
43+ > is automatically registered as part of the Laravel service discovery.
2444
25- ## Configuration
45+ ### Generate migrations, controllers and models
2646
27- Scaffold the controllers, migrations and models.
47+ The package provides the login and registration features via traits.
48+ Once the ` oneofftech/laravel-connect-identity ` package has been installed,
49+ you can generate the controllers, models and migrations scaffolding using the
50+ ` ui:identities ` Artisan command:
2851
2952```
3053php artisan ui:identities
3154```
3255
33- Add the WithIdentities trait to your User model to use the ` identities ` relationship.
56+ Now you can add the ` WithIdentities ` trait to your ` User ` model. This is required
57+ to use the ` identities ` relationship required during the registration/login process.
3458
3559``` php
3660// ...
@@ -39,33 +63,26 @@ use Oneofftech\Identities\WithIdentities;
3963
4064class User extends Authenticatable
4165{
42- use Notifiable, WithIdentities;
66+ use WithIdentities;
4367
4468 // ...
4569}
4670```
4771
72+ > If your application has a different namespace than ` App ` please refer
73+ to [ Using a personalized application namespace] ( #using-a-personalized-application-namespace )
74+ for additional required setup actions.
4875
49- Register the events to your events service provider.
76+ ### Configure the Socialite providers
5077
51- > This will register the SocialiteWasCalled event for the Gitlab and Dropbox
52- providers that are included by default. If you are not using those providers
53- this step is optional.
78+ Before using an identity provider, e.g. ` facebook ` , ` google ` , ` github ` , ` gitlab ` ,
79+ configure the required options inside the ` services ` configuration file.
5480
55- ```
56- \Oneofftech\Identities\Facades\Identity::events();
57- ```
58-
59- public function boot()
60- {
61- parent::boot();
62-
63- \Oneofftech\Identities\Facades\Identity::events();
64- }
65-
66-
67- Inserire i valori nei services secondo le specifiche di Laravel Socialite
81+ > To see the driver specific configuration please refer to
82+ [ Laravel's documentation] ( https://laravel.com/docs/socialite ) or the
83+ [ Socialite Providers documentation] ( https://socialiteproviders.com/ ) .
6884
85+ > The ` redirect ` url configuration is not required as the redirect url is set automatically.
6986
7087``` php
7188 'gitlab' => [
@@ -76,13 +93,67 @@ Inserire i valori nei services secondo le specifiche di Laravel Socialite
7693 ],
7794```
7895
96+ If you are using one of the community maintained [ Socialite Providers] ( https://socialiteproviders.com/ )
97+ remember to register their events in your ` EventsServiceProvider ` .
98+
99+ If you are not using those providers this step is optional.
100+
101+ ` oneofftech/laravel-connect-identity ` provides out-of-the-box support for the ` gitlab `
102+ and ` dropbox ` driver. If you are using those two you might add the following call to
103+ your ` EventsServiceProvider ` .
104+
105+ ``` php
106+
107+ public function boot()
108+ {
109+ parent::boot();
110+
111+ \Oneofftech\Identities\Facades\Identity::events();
112+ }
113+ ```
114+
115+ This will register the ` SocialiteWasCalled ` event for the Gitlab and Dropbox
116+ providers that are included by default.
117+
118+
119+ ### Include the login and register buttons
120+
121+ ` oneofftech/laravel-connect-identity ` does not dictate your User Interface preferences,
122+ however we provide a Blade Component to quickly add login and register links/buttons.
123+
124+ ``` html
125+ <x-oneofftech-identity-link
126+ action =" register"
127+ provider =" gitlab"
128+ class =" button button--primary" />
129+ ```
130+
131+ The available ` action ` s are ` login ` and ` register ` . The ` provider ` refers to what
132+ identity provider to use, the name of the provider is the same as the Socialite
133+ providers' name. See [ Blade components] ( https://laravel.com/docs/blade#components ) for more.
134+
135+ In case of errors, mainly connected to validation, you can catch those by looking at
136+ the used provider key in the Laravel default ErrorBag.
137+
138+ ``` html
139+ @error('gitlab')
140+ <span class =" field-error" role =" alert" >
141+ {{ $message }}
142+ </span >
143+ @enderror
144+ ```
145+
146+ ## Digging Deeper
79147
80148### Using a personalized application namespace
81149
150+ While the ` ui:identities ` command is namespace aware some of the runtime configuration
151+ is not.
152+
82153If you are using a custom application namespace instead of the default ` App ` ,
83154you need to tell which namespace and models to use.
84155
85- To do so add the following lines in your AppServiceProvider;
156+ To do so add the following lines in your ` AppServiceProvider ` ;
86157
87158``` php
88159
@@ -93,21 +164,81 @@ class AppServiceProvider extends ServiceProvider
93164
94165 public function boot()
95166 {
96- Identity::useNamespace("KBox \\");
97- Identity::useIdentityModel("KBox \\Identity");
98- Identity::useUserModel("KBox \\User");
167+ Identity::useNamespace("My\\Namespace \\");
168+ Identity::useIdentityModel("My\\Namespace \\Identity");
169+ Identity::useUserModel("My\\Namespace \\User");
99170
100171 // ...
101172 }
102173}
103174```
104175
105- The ` ui:identities ` command is namespace aware.
176+ ### Passing additional data to the registration
177+
178+ Sometimes you will need additional parameters do create a user after the authorization
179+ process on the third party service. To do so you can add as many parameters in the
180+ request made to the register route that redirects to the third party service.
181+
182+ By default additional request parameters are guarded and so you have to explicitly
183+ tell their name. You can do this by defining an ` attributes ` property or an
184+ ` attributes ` method on the ` RegisterController ` that returns an array of strings
185+ that represent the name of the allowed parameters.
186+
187+ ``` php
188+ protected $attributes = ['name'];
189+
190+ protected function attributes()
191+ {
192+ return ['name'];
193+ }
194+ ```
195+
196+ The additional attributes will then passed to the ` validator(array $data) ` and
197+ ` create(array $data) ` function defined within the ` RegisterController ` .
198+
199+ If you are using the provided ` IdentityLink ` Blade component the data should
200+ be specified as associative array inside the ` parameters ` property.
201+
202+ ``` html
203+ <x-oneofftech-identity-link
204+ action =" register"
205+ provider =" gitlab"
206+ :parameters =" $arrayOfAdditionalParameters"
207+ class =" button button--primary" />
208+ ```
209+
210+ Where ` $arrayOfAdditionalParameters ` is an associative array, e.g. ` ['invite' => 'token_value'] ` .
211+
212+ ### How data is stored in the database
213+
214+ Whenever possible data is stored encrypted or in a pseudo-anonymized form.
215+
216+ Encryption works by using the [ Laravel's Encryption] ( https://laravel.com/docs/encryption ) and the configured
217+ application key (i.e. ` APP_KEY ` ). If you want to use a different key use the ` IDENTITY_KEY ` environment variable, the
218+ used cipher will be the same as configured in ` app.cipher ` .
219+
220+ The pseudo-anonymized values are stored as hashes of the original data.
221+
222+ Here is how sensible data is stored:
223+
224+ | data | technique |
225+ | ---------------------------------------| -------------------|
226+ | identifier within third party service | pseudo-anonymized |
227+ | authentication token | encrypted |
228+ | refresh token | encrypted |
229+
230+ > If you need to [ rotate the APP_KEY] ( https://divinglaravel.com/app_key-is-a-secret-heres-what-its-used-for-how-you-can-rotate-it )
231+ specify your old key inside ` OLD_IDENTITY_KEY ` to be able to still read encrypted values.
232+
233+ > ** Warning** as of now no automated job is available for re-encrypting data with the new key.
234+ This operation happens during a login or a registration process as part of the token update.
235+
106236
237+ ## Contributing
107238
108- ## Basic Usage
239+ All types of contribution are accepted, bug-fix, documentation updates, new features!
109240
110- .. .
241+ We will have a contributing page soon, but meanwhile you can submit Pull Requests .
111242
112243## License
113244
0 commit comments