Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F8100173
SimpleJwtBuilder.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
SimpleJwtBuilder.php
View Options
<?php
namespace
MediaWiki\Json
;
use
Lcobucci\JWT\ClaimsFormatter
;
use
Lcobucci\JWT\Encoder
;
use
Lcobucci\JWT\Signer
;
use
Lcobucci\JWT\Signer\Key
;
use
Lcobucci\JWT\Token\DataSet
;
use
Lcobucci\JWT\Token\Plain
;
use
Lcobucci\JWT\Token\Signature
;
/**
* Duplicates the logic from lcobucci/jwt's Builder class, without the annoying syntax that makes
* it really hard to decouple the MediaWiki callers from the library.
* @since 1.45
* @see https://github.com/lcobucci/jwt/blob/4.1.5/src/Token/Builder.php
*/
class
SimpleJwtBuilder
{
private
array
$headers
=
[
'typ'
=>
'JWT'
,
'alg'
=>
null
];
/** @var array<string, mixed> */
private
array
$claims
=
[];
public
function
__construct
(
private
Encoder
$encoder
,
private
ClaimsFormatter
$claimFormatter
)
{
}
public
function
setClaims
(
array
$claims
):
void
{
$this
->
claims
=
$claims
;
}
public
function
getToken
(
Signer
$signer
,
Key
$key
):
Plain
{
$headers
=
$this
->
headers
;
$headers
[
'alg'
]
=
$signer
->
algorithmId
();
$encodedHeaders
=
$this
->
encode
(
$headers
);
$encodedClaims
=
$this
->
encode
(
$this
->
claimFormatter
->
formatClaims
(
$this
->
claims
)
);
$signature
=
$signer
->
sign
(
$encodedHeaders
.
'.'
.
$encodedClaims
,
$key
);
$encodedSignature
=
$this
->
encoder
->
base64UrlEncode
(
$signature
);
return
new
Plain
(
new
DataSet
(
$headers
,
$encodedHeaders
),
new
DataSet
(
$this
->
claims
,
$encodedClaims
),
new
Signature
(
$signature
,
$encodedSignature
),
);
}
private
function
encode
(
array
$items
):
string
{
return
$this
->
encoder
->
base64UrlEncode
(
$this
->
encoder
->
jsonEncode
(
$items
)
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Dec 8, 01:58 (1 d, 13 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c0/4a/bd16572f8add884fb9125507bf38
Default Alt Text
SimpleJwtBuilder.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment