1616
1717use Lcobucci \JWT \Builder ;
1818use Lcobucci \JWT \Signer \Key ;
19- use Lcobucci \JWT \Signer \Rsa \Sha256 ;
2019use League \OAuth2 \Server \Entities \AccessTokenEntityInterface ;
2120use League \OAuth2 \Server \Entities \ScopeEntityInterface ;
2221use League \OAuth2 \Server \Entities \UserEntityInterface ;
2322use League \OAuth2 \Server \ResponseTypes \BearerTokenResponse ;
2423use OpenIDConnectServer \ClaimExtractor ;
2524use OpenIDConnectServer \Entities \ClaimSetInterface ;
2625use OpenIDConnectServer \Repositories \IdentityProviderInterface ;
26+ use SimpleSAML \Modules \OpenIDConnect \Services \ConfigurationService ;
2727
2828/**
2929 * Class IdTokenResponse.
@@ -45,18 +45,18 @@ class IdTokenResponse extends BearerTokenResponse
4545 */
4646 protected $ claimExtractor ;
4747 /**
48- * @var Builder
48+ * @var ConfigurationService
4949 */
50- private $ builder ;
50+ private $ configurationService ;
5151
5252 public function __construct (
5353 IdentityProviderInterface $ identityProvider ,
5454 ClaimExtractor $ claimExtractor ,
55- Builder $ builder
55+ ConfigurationService $ configurationService
5656 ) {
5757 $ this ->identityProvider = $ identityProvider ;
5858 $ this ->claimExtractor = $ claimExtractor ;
59- $ this ->builder = $ builder ;
59+ $ this ->configurationService = $ configurationService ;
6060 }
6161
6262 /**
@@ -78,12 +78,7 @@ protected function getExtraParams(AccessTokenEntityInterface $accessToken)
7878 }
7979
8080 // Add required id_token claims
81- $ builder = $ this ->builder
82- ->permittedFor ($ accessToken ->getClient ()->getIdentifier ())
83- ->issuedAt (time ())
84- ->expiresAt ($ accessToken ->getExpiryDateTime ()->getTimestamp ())
85- ->relatedTo ($ userEntity ->getIdentifier ())
86- ;
81+ $ builder = $ this ->getBuilder ($ accessToken , $ userEntity );
8782
8883 // Need a claim factory here to reduce the number of claims by provided scope.
8984 $ claims = $ this ->claimExtractor ->extract ($ accessToken ->getScopes (), $ userEntity ->getClaims ());
@@ -92,14 +87,29 @@ protected function getExtraParams(AccessTokenEntityInterface $accessToken)
9287 $ builder ->withClaim ($ claimName , $ claimValue );
9388 }
9489
95- $ key = new Key ($ this ->privateKey ->getKeyPath (), $ this ->privateKey ->getPassPhrase ());
96- $ token = $ builder ->getToken (new Sha256 (), $ key );
90+ $ token = $ builder ->getToken (
91+ $ this ->configurationService ->getSigner (),
92+ new Key ($ this ->privateKey ->getKeyPath (), $ this ->privateKey ->getPassPhrase ())
93+ );
9794
9895 return [
9996 'id_token ' => (string ) $ token ,
10097 ];
10198 }
10299
100+ protected function getBuilder (AccessTokenEntityInterface $ accessToken , UserEntityInterface $ userEntity )
101+ {
102+ return (new Builder ())
103+ ->issuedBy ($ this ->configurationService ->getSimpleSAMLSelfURLHost ())
104+ ->permittedFor ($ accessToken ->getClient ()->getIdentifier ())
105+ ->identifiedBy ($ accessToken ->getIdentifier ())
106+ ->canOnlyBeUsedAfter (\time ())
107+ ->expiresAt ($ accessToken ->getExpiryDateTime ()->getTimestamp ())
108+ ->relatedTo ($ userEntity ->getIdentifier ())
109+ ->issuedAt (\time ())
110+ ->withHeader ('kid ' , '0 ' );
111+ }
112+
103113 /**
104114 * @param ScopeEntityInterface[] $scopes
105115 *
0 commit comments