-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from DirectoryTree/provider-tokens
Add ability to store Socialite provider tokens
- Loading branch information
Showing
7 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
database/migrations/2024_10_27_131354_add_provider_token_columns_to_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->after('provider_name', function (Blueprint $table) { | ||
$table->string('provider_access_token')->nullable(); | ||
$table->string('provider_refresh_token')->nullable(); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn([ | ||
'provider_access_token', | ||
'provider_refresh_token', | ||
]); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
namespace DirectoryTree\Bartender; | ||
|
||
interface StoresProviderTokens {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,8 @@ | |
$user->id = '1'; | ||
$user->name = 'foo'; | ||
$user->email = '[email protected]'; | ||
$user->token = '1234'; | ||
$user->refreshToken = '2345'; | ||
}); | ||
|
||
$user = (new UserProviderRepository)->updateOrCreate('foo', $socialite); | ||
|
@@ -57,6 +59,8 @@ | |
expect($user->email)->toBe('[email protected]'); | ||
expect($user->provider_id)->toBe('1'); | ||
expect($user->provider_name)->toBe('foo'); | ||
expect($user->provider_access_token)->toBe('1234'); | ||
expect($user->provider_refresh_token)->toBe('2345'); | ||
}); | ||
|
||
it('updates user not associated to provider', function () { | ||
|
@@ -81,6 +85,8 @@ | |
expect($user->email)->toBe('[email protected]'); | ||
expect($user->provider_id)->toBe('1'); | ||
expect($user->provider_name)->toBe('foo'); | ||
expect($user->provider_access_token)->toBeNull(); | ||
expect($user->provider_refresh_token)->toBeNull(); | ||
}); | ||
|
||
it('throws exception when attempting to create existing user with null provider', function () { | ||
|