Skip to content

Commit cc27057

Browse files
committed
Update README.md
1 parent 1e29b8e commit cc27057

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

README.md

+65-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Almost everything in Bartender can be customized.
2525
- [Installation](#installation)
2626
- [Setup](#setup)
2727
- [Usage](#usage)
28+
- [Soft Deletes](#soft-deletes)
29+
- [Email Verification](#email-verification)
30+
- [Access/Refresh Tokens](#accessrefresh-tokens)
2831
- [Extending & Customizing](#extending--customizing)
2932

3033
## Requirements
@@ -41,9 +44,14 @@ You can install the package via composer:
4144
composer require directorytree/bartender
4245
```
4346

44-
Then, publish the migration:
47+
Then, publish the migrations. They will create the required columns on the `users` table:
4548

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.
4755
4856
```bash
4957
php artisan vendor:publish --provider="DirectoryTree\Bartender\BartenderServiceProvider"
@@ -164,10 +172,62 @@ To change this behaviour, [swap out the repository](#user-creation--updating).
164172

165173
### Email Verification
166174

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.
168176

169177
To change this behaviour, [swap out the repository](#user-creation--updating).
170178

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 in such case.
230+
171231
## Extending & Customizing
172232

173233
Almost everything can be swapped out in Bartender.
@@ -242,6 +302,8 @@ You may also extend the built-in `UserProviderHandler` implementation if you pre
242302
For example, if you need to adjust the scopes for a single provider:
243303

244304
```php
305+
// app/Socialite/MicrosoftUserHandler.php
306+
245307
namespace App\Socialite;
246308

247309
use Illuminate\Http\RedirectResponse;

0 commit comments

Comments
 (0)