WC_API_Authentication::authenticate()
Authenticate the request. The authentication method varies based on whether the request was made over SSL or not.
Method of the class: WC_API_Authentication{}
No Hooks.
Return
null|WP_Error|WP_User
.
Usage
$WC_API_Authentication = new WC_API_Authentication(); $WC_API_Authentication->authenticate( $user );
- $user(WP_User) (required)
- -
Changelog
Since 2.1 | Introduced. |
WC_API_Authentication::authenticate() WC API Authentication::authenticate code WC 7.7.0
public function authenticate( $user ) { // Allow access to the index by default if ( '/' === WC()->api->server->path ) { return new WP_User( 0 ); } try { if ( is_ssl() ) { $keys = $this->perform_ssl_authentication(); } else { $keys = $this->perform_oauth_authentication(); } // Check API key-specific permission $this->check_api_key_permissions( $keys['permissions'] ); $user = $this->get_user_by_id( $keys['user_id'] ); $this->update_api_key_last_access( $keys['key_id'] ); } catch ( Exception $e ) { $user = new WP_Error( 'woocommerce_api_authentication_error', $e->getMessage(), array( 'status' => $e->getCode() ) ); } return $user; }