-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync authentication token with tbp-consumer-api (#3)
## Motivation The Consumer API needs to get some verification token to validate if the user should send the metrics heartbeat. Now the platform also syncs the user token which will expires together.
- Loading branch information
1 parent
6049777
commit 21d8fb9
Showing
7 changed files
with
155 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Clients\Consumer\DTO; | ||
|
||
use App\DTO\AuthorizationDTO; | ||
|
||
readonly class UserTokenDTO | ||
{ | ||
public function __construct( | ||
public AuthorizationDTO $authDTO, | ||
public int $userId, | ||
) {} | ||
|
||
public static function factory(AuthorizationDTO $authenticationDTO, int $userId): UserTokenDTO | ||
{ | ||
return new UserTokenDTO( | ||
authDTO: $authenticationDTO, | ||
userId: $userId, | ||
); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace App\DTO; | ||
|
||
use App\Models\User; | ||
|
||
readonly class AuthenticationDTO | ||
{ | ||
public function __construct( | ||
public AuthorizationDTO $authorization, | ||
public User $user, | ||
) {} | ||
|
||
public static function factory(AuthorizationDTO $authorization, User $user): AuthenticationDTO | ||
{ | ||
return new AuthenticationDTO( | ||
authorization: $authorization, | ||
user: $user, | ||
); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace App\DTO; | ||
|
||
use Carbon\Carbon; | ||
|
||
readonly class AuthorizationDTO implements \JsonSerializable | ||
{ | ||
public function __construct( | ||
public string $accessToken, | ||
public Carbon $expiresAt, | ||
public string $token = 'Bearer', | ||
) {} | ||
|
||
public static function factory($accessToken, $expiresAt): AuthorizationDTO | ||
{ | ||
return new AuthorizationDTO( | ||
accessToken: $accessToken, | ||
expiresAt: $expiresAt, | ||
); | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'access_token' => $this->accessToken, | ||
'token_type' => $this->token, | ||
'expires_at' => $this->expiresAt->toIso8601String(), | ||
]; | ||
} | ||
} |
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