1010use Illuminate \Support \Str ;
1111use Laravel \Socialite \Two \InvalidStateException ;
1212use Lcobucci \Clock \SystemClock ;
13- use Lcobucci \JWT \Configuration ;
13+ use Lcobucci \JWT \Encoding \JoseEncoder ;
14+ use Lcobucci \JWT \Exception ;
15+ use Lcobucci \JWT \Signer \Key \InMemory ;
1416use Lcobucci \JWT \Signer \Rsa \Sha256 ;
17+ use Lcobucci \JWT \Token \Parser ;
1518use Lcobucci \JWT \Validation \Constraint \IssuedBy ;
1619use Lcobucci \JWT \Validation \Constraint \LooseValidAt ;
1720use Lcobucci \JWT \Validation \Constraint \SignedWith ;
18- use Lcobucci \JWT \Validation \RequiredConstraintsViolated ;
21+ use Lcobucci \JWT \Validation \Validator ;
1922use Psr \Http \Message \ResponseInterface ;
2023use SocialiteProviders \Manager \OAuth2 \AbstractProvider ;
2124use SocialiteProviders \Manager \OAuth2 \User ;
@@ -119,11 +122,11 @@ public function userByIdentityToken(string $token): User
119122 */
120123 public static function verify ($ jwt )
121124 {
122- $ jwtContainer = Configuration:: forSymmetricSigner (
123- new AppleSignerNone ,
124- AppleSignerInMemory:: plainText ( '' )
125- );
126- $ token = $ jwtContainer -> parser ()-> parse ( $ jwt );
125+ try {
126+ $ token = ( new Parser ( new JoseEncoder ()))-> parse ( $ jwt );
127+ } catch ( Exception $ e ) {
128+ throw new InvalidStateException ( $ e -> getMessage () );
129+ }
127130
128131 $ data = Cache::remember ('socialite:Apple-JWKSet ' , 5 * 60 , function () {
129132 $ response = (new Client )->get (self ::URL .'/auth/keys ' );
@@ -134,24 +137,23 @@ public static function verify($jwt)
134137 $ publicKeys = JWK ::parseKeySet ($ data );
135138 $ kid = $ token ->headers ()->get ('kid ' );
136139
137- if (isset ($ publicKeys [$ kid ])) {
138- $ publicKey = openssl_pkey_get_details ($ publicKeys [$ kid ]->getKeyMaterial ());
140+ if (!isset ($ publicKeys [$ kid ])) {
141+ throw new InvalidStateException ('Invalid JWT Signature ' );
142+ }
143+
144+ $ publicKey = openssl_pkey_get_details ($ publicKeys [$ kid ]->getKeyMaterial ());
145+ try {
139146 $ constraints = [
140- new SignedWith (new Sha256 , AppleSignerInMemory ::plainText ($ publicKey ['key ' ])),
147+ new SignedWith (new Sha256 , InMemory ::plainText ($ publicKey ['key ' ])),
141148 new IssuedBy (self ::URL ),
142149 new LooseValidAt (SystemClock::fromSystemTimezone ()),
143150 ];
144151
145- try {
146- $ jwtContainer ->validator ()->assert ($ token , ...$ constraints );
147-
148- return true ;
149- } catch (RequiredConstraintsViolated $ e ) {
150- throw new InvalidStateException ($ e ->getMessage ());
151- }
152+ (new Validator ())->assert ($ token , ...$ constraints );
153+ } catch (Exception $ e ) {
154+ throw new InvalidStateException ($ e ->getMessage ());
152155 }
153-
154- throw new InvalidStateException ('Invalid JWT Signature ' );
156+ return true ;
155157 }
156158
157159 /**
0 commit comments