@@ -69,30 +69,34 @@ public static function setAuthenticationSchemes(array $authenticationSchemesClas
6969 );
7070 }
7171 });
72- static ::$ authenticationSchemesClasses = $ authenticationSchemesClasses ;
72+ $ types = array_map (function (AbstractAuthorizationHeader $ v ) {
73+ return $ v ::getAuthorizationType ();
74+ }, $ authenticationSchemesClasses );
75+
76+ static ::$ authenticationSchemesClasses = array_combine ($ types , $ authenticationSchemesClasses );
7377 }
7478
75- public static function getAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
79+ public static function getFirstAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
7680 {
7781 $ header = $ message ->getHeader ('Authorization ' );
7882
7983 if (empty ($ header )) {
8084 return null ;
8185 }
8286
87+ $ header = current ($ header );
88+
8389 $ wsp = strpos ($ header , ' ' );
8490 $ type = ucfirst (strtolower (substr ($ header , 0 , $ wsp )));
8591 $ content = substr ($ header , $ wsp + 1 );
8692
87- foreach (static ::$ authenticationSchemesClasses as $ auSch ) {
88- if (strcasecmp ($ type , $ auSch ::getAuthorizationType ()) !== 0 ) {
89- continue ;
90- }
91- $ authHeader = new $ auSch ();
92- return $ authHeader ->withCredentials ($ content );
93+ if (!array_key_exists ($ type , static ::$ authenticationSchemesClasses )) {
94+ return null ;
9395 }
96+ $ authSch = static ::$ authenticationSchemesClasses [$ type ];
9497
95- return null ;
98+ $ authHeader = new $ authSch ();
99+ return $ authHeader ->withCredentials ($ content );
96100 }
97101
98102 public static function getContent (MessageInterface $ message )
0 commit comments