-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75f5d24
commit 2ea80c6
Showing
2 changed files
with
39 additions
and
28 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,38 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace AtlassianConnectBundle\Service; | ||
|
||
use Firebase\JWT\JWT; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
/** | ||
* Class JWTGenerator | ||
*/ | ||
class JWTGenerator | ||
{ | ||
/** | ||
* Create JWT token used by Atlassian REST API request | ||
* | ||
* @param RequestInterface $request | ||
* @param string $issuer Key of the add-on | ||
* @param string $secret Shared secret of the Tenant | ||
* @param null|string $user | ||
* | ||
* @return string | ||
*/ | ||
public static function generate(RequestInterface $request, string $issuer, string $secret, ?string $user): string | ||
{ | ||
$data = [ | ||
'iss' => $issuer, | ||
'iat' => \time(), | ||
'exp' => \strtotime('+1 day'), | ||
'qsh' => QSHGenerator::generate((string) $request->getUri(), $request->getMethod()), | ||
]; | ||
|
||
if ($user !== null) { | ||
$data['sub'] = $user; | ||
} | ||
|
||
return JWT::encode($data, $secret); | ||
} | ||
} |