WC_REST_Authentication::parse_header
Parse the Authorization header into parameters.
Method of the class: WC_REST_Authentication{}
No Hooks.
Returns
Array. Map of parameter values.
Usage
$WC_REST_Authentication = new WC_REST_Authentication(); $WC_REST_Authentication->parse_header( $header );
- $header(string) (required)
- Authorization header value (not including "Authorization: " prefix).
Changelog
| Since 3.0.0 | Introduced. |
WC_REST_Authentication::parse_header() WC REST Authentication::parse header code WC 10.7.0
public function parse_header( $header ) {
if ( 'OAuth ' !== substr( $header, 0, 6 ) ) {
return array();
}
// From OAuth PHP library, used under MIT license.
$params = array();
if ( preg_match_all( '/(oauth_[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches ) ) {
foreach ( $matches[1] as $i => $h ) {
$params[ $h ] = urldecode( empty( $matches[3][ $i ] ) ? $matches[4][ $i ] : $matches[3][ $i ] );
}
if ( isset( $params['realm'] ) ) {
unset( $params['realm'] );
}
}
return $params;
}