You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -41,9 +44,14 @@ You can install the package via composer:
41
44
composer require directorytree/bartender
42
45
```
43
46
44
-
Then, publish the migration:
47
+
Then, publish the migrations. They will create the required columns on the `users` table:
45
48
46
-
> It creates the `provider_id` and `provider_name` column on the `users` table.
49
+
-`provider_id`
50
+
-`provider_name`
51
+
-`provider_access_token`
52
+
-`provider_refresh_token`
53
+
54
+
> If your application does not need to store/access provider tokens, you may delete the `2024_10_27_131354_add_provider_token_columns_to_users_table.php` migration.
@@ -164,10 +172,63 @@ To change this behaviour, [swap out the repository](#user-creation--updating).
164
172
165
173
### Email Verification
166
174
167
-
With the default `UserProviderRepository`, users will emails will be automatically verified (via the `email_verified_at` column) if it is not already set.
175
+
With the default `UserProviderRepository`, users with emails will be automatically verified (via the `email_verified_at` column) if it is not already set.
168
176
169
177
To change this behaviour, [swap out the repository](#user-creation--updating).
170
178
179
+
### Access/Refresh Tokens
180
+
181
+
To enable storing the authentication provider access and refresh tokens
182
+
on your user so that you can access them later, you may apply the
183
+
`StoresProviderTokens` interface on your model:
184
+
185
+
```php
186
+
// app/Models/User.php
187
+
188
+
namespace App\Models;
189
+
190
+
use DirectoryTree\Bartender\StoresProviderTokens;
191
+
192
+
class User extends Authenticatable implements StoresProviderTokens
193
+
{
194
+
// ...
195
+
}
196
+
```
197
+
198
+
You may also want to add these columns to your model's `$hidden` attributes, as well as `encrypted` casts for additional security:
199
+
200
+
```php
201
+
// app/Models/User.php
202
+
203
+
class User extends Authenticatable implements StoresProviderTokens
204
+
{
205
+
/**
206
+
* The attributes that should be hidden for serialization.
207
+
*/
208
+
protected $hidden = [
209
+
'provider_access_token',
210
+
'provider_refresh_token'
211
+
];
212
+
213
+
/**
214
+
* Get the attributes that should be cast.
215
+
*/
216
+
protected function casts(): array
217
+
{
218
+
return [
219
+
'provider_access_token' => 'encrypted',
220
+
'provider_refresh_token' => 'encrypted',
221
+
];
222
+
}
223
+
}
224
+
```
225
+
226
+
Otherwise, if you do not need to store these tokens, you are free to delete the
227
+
published `2024_10_27_131354_add_provider_token_columns_to_users_table.php`
228
+
migration file and omit applying the `StoresProviderTokens` interface.
229
+
Bartender will skip storing these tokens as it does not
230
+
require them to successfully authenticate users.
231
+
171
232
## Extending & Customizing
172
233
173
234
Almost everything can be swapped out in Bartender.
@@ -242,6 +303,8 @@ You may also extend the built-in `UserProviderHandler` implementation if you pre
242
303
For example, if you need to adjust the scopes for a single provider:
0 commit comments