-
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 #77 from daniel-de-wit/configurable-credential-keys
Ability to customize credential keys e.g: email/username
- Loading branch information
Showing
9 changed files
with
119 additions
and
5 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
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
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 |
---|---|---|
|
@@ -45,6 +45,7 @@ public function it_sends_a_reset_password_notification(): void | |
]); | ||
|
||
Notification::assertSentTo($user, function (ResetPassword $notification) use ($user) { | ||
/** @phpstan-ignore-next-line */ | ||
$url = call_user_func($notification::$createUrlCallback, $user, $notification->token); | ||
|
||
return $url === "https://my-front-end.com/[email protected]&token={$notification->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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ public function it_sets_the_reset_password_url(): void | |
|
||
$this->service->setResetPasswordUrl('https://mysite.com/reset-password/__EMAIL__/__TOKEN__'); | ||
|
||
/** @phpstan-ignore-next-line */ | ||
$url = call_user_func(ResetPassword::$createUrlCallback, $user, $token); | ||
|
||
static::assertSame('https://mysite.com/reset-password/[email protected]/token123', $url); | ||
|
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use DanielDeWit\LighthouseSanctum\Tests\Traits\MocksUserProvider; | ||
use DanielDeWit\LighthouseSanctum\Tests\Unit\AbstractUnitTest; | ||
use Illuminate\Contracts\Auth\UserProvider; | ||
use Illuminate\Contracts\Config\Repository as Config; | ||
use Illuminate\Foundation\Auth\User; | ||
use Laravel\Sanctum\NewAccessToken; | ||
use Mockery; | ||
|
@@ -62,6 +63,64 @@ public function it_logs_a_user_in(): void | |
static::assertSame('1234567890', $result['token']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_logs_a_user_in_using_custom_identification(): void | ||
{ | ||
/** @var Config|MockInterface $config */ | ||
$config = Mockery::mock(Config::class) | ||
->shouldReceive('get') | ||
->with('lighthouse-sanctum.provider') | ||
->andReturn('sanctum-provider') | ||
->getMock() | ||
->shouldReceive('get') | ||
->with('lighthouse-sanctum.identification.user_identifier_field_name', 'email') | ||
->andReturn('custom_key') | ||
->getMock(); | ||
|
||
$token = Mockery::mock(NewAccessToken::class); | ||
$token->plainTextToken = '1234567890'; | ||
|
||
/** @var UserHasApiTokens|MockInterface $user */ | ||
$user = Mockery::mock(UserHasApiTokens::class) | ||
->shouldReceive('createToken') | ||
->with('default') | ||
->andReturn($token) | ||
->getMock(); | ||
|
||
/** @var UserProvider|MockInterface $userProvider */ | ||
$userProvider = Mockery::mock(UserProvider::class) | ||
->shouldReceive('retrieveByCredentials') | ||
->with([ | ||
'custom_key' => '[email protected]', | ||
'password' => 'supersecret', | ||
]) | ||
->andReturn($user) | ||
->getMock() | ||
->shouldReceive('validateCredentials') | ||
->with($user, [ | ||
'custom_key' => '[email protected]', | ||
'password' => 'supersecret', | ||
]) | ||
->andReturnTrue() | ||
->getMock(); | ||
|
||
$mutation = new Login( | ||
$this->mockAuthManager($userProvider), | ||
$config, | ||
); | ||
|
||
$result = $mutation(null, [ | ||
'custom_key' => '[email protected]', | ||
'password' => 'supersecret', | ||
]); | ||
|
||
static::assertIsArray($result); | ||
static::assertCount(1, $result); | ||
static::assertSame('1234567890', $result['token']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
|
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