diff --git a/flexiapi/app/Http/Middleware/AuthenticateJWT.php b/flexiapi/app/Http/Middleware/AuthenticateJWT.php index b1eb0fb..4981061 100644 --- a/flexiapi/app/Http/Middleware/AuthenticateJWT.php +++ b/flexiapi/app/Http/Middleware/AuthenticateJWT.php @@ -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) diff --git a/flexiapi/tests/Feature/AccountJWTAuthenticationTest.php b/flexiapi/tests/Feature/AccountJWTAuthenticationTest.php index 4d067ad..2ae4622 100644 --- a/flexiapi/tests/Feature/AccountJWTAuthenticationTest.php +++ b/flexiapi/tests/Feature/AccountJWTAuthenticationTest.php @@ -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);