@@ -69,30 +69,34 @@ public static function setAuthenticationSchemes(array $authenticationSchemesClas
69
69
);
70
70
}
71
71
});
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 );
73
77
}
74
78
75
- public static function getAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
79
+ public static function getFirstAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
76
80
{
77
81
$ header = $ message ->getHeader ('Authorization ' );
78
82
79
83
if (empty ($ header )) {
80
84
return null ;
81
85
}
82
86
87
+ $ header = current ($ header );
88
+
83
89
$ wsp = strpos ($ header , ' ' );
84
90
$ type = ucfirst (strtolower (substr ($ header , 0 , $ wsp )));
85
91
$ content = substr ($ header , $ wsp + 1 );
86
92
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 ;
93
95
}
96
+ $ authSch = static ::$ authenticationSchemesClasses [$ type ];
94
97
95
- return null ;
98
+ $ authHeader = new $ authSch ();
99
+ return $ authHeader ->withCredentials ($ content );
96
100
}
97
101
98
102
public static function getContent (MessageInterface $ message )
0 commit comments