Fix FLEXIAPI-430 Handle empty string in JWT_SIP_IDENTIFIER and fallback to sip_identity

This commit is contained in:
Timothée Jaussoin 2026-01-06 15:23:41 +01:00
parent 06dc357524
commit f883c3cee7
2 changed files with 18 additions and 2 deletions

View file

@ -76,9 +76,11 @@ class AuthenticateJWT
}
$account = null;
$identifierKey = config('services.jwt.sip_identifier');
if ($identifierKey == '') $identifierKey = 'sip_identity';
if ($token->claims()->has(config('services.jwt.sip_identifier'))) {
list($username, $domain) = parseSIP($token->claims()->get(config('services.jwt.sip_identifier')));
if ($token->claims()->has($identifierKey)) {
list($username, $domain) = parseSIP($token->claims()->get($identifierKey));
$account = Account::withoutGlobalScopes()
->where('username', $username)

View file

@ -93,6 +93,20 @@ class AccountJWTAuthenticationTest extends TestCase
$this->checkToken($token);
// Handle JWT_SIP_IDENTIFIER=
config()->set('services.jwt.sip_identifier', '');
$token = (new JwtFacade(null, $clock))->issue(
new Sha256(),
InMemory::plainText($this->serverPrivateKeyPem),
static fn (
Builder $builder,
DateTimeImmutable $issuedAt
): Builder => $builder->withClaim('sip_identity', 'sip:' . $password->account->username . '@' . $password->account->domain)
);
$this->checkToken($token);
// Custom SIP identifier
$otherIdentifier = 'sip_other_identifier';
config()->set('services.jwt.sip_identifier', $otherIdentifier);