Changeset 10226 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php
- Timestamp:
- 09/01/2020 05:08:48 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/class-base.php
r10214 r10226 60 60 61 61 /** 62 * A Permission Check callback which validates the request with a Bearertoken.62 * A Permission Check callback which validates the request against the internal api-call token. 63 63 * 64 64 * @param \WP_REST_Request $request The Rest API Request. … … 66 66 */ 67 67 function permission_check_internal_api_bearer( $request ) { 68 return $this->permission_check_api_bearer( $request, 'PLUGIN_API_INTERNAL_BEARER_TOKEN' ); 69 } 70 71 /** 72 * A Permission Check callback which validates the request against a GitHub specific token. 73 * 74 * @param \WP_REST_Request $request The Rest API Request. 75 * @return bool|\WP_Error True if the token exists, WP_Error upon failure. 76 */ 77 function permission_check_github_api_bearer( $request ) { 78 return $this->permission_check_api_bearer( $request, 'PLUGIN_API_GITHUB_BEARER_TOKEN' ); 79 } 80 81 /** 82 * A Permission Check callback which validates the a request against a given token. 83 * 84 * @param \WP_REST_Request $request The Rest API Request. 85 * @param string $constant The constant that contains the expected bearer. 86 * @return bool|\WP_Error True if the token exists, WP_Error upon failure. 87 */ 88 function permission_check_api_bearer( $request, $constant = false ) { 68 89 $authorization_header = $request->get_header( 'authorization' ); 69 90 $authorization_header = trim( str_ireplace( 'bearer', '', $authorization_header ) ); … … 71 92 if ( 72 93 ! $authorization_header || 73 ! defined( 'PLUGIN_API_INTERNAL_BEARER_TOKEN' ) || 74 ! hash_equals( PLUGIN_API_INTERNAL_BEARER_TOKEN, $authorization_header ) 94 ! $constant || 95 ! defined( $constant ) || 96 ! hash_equals( constant( $constant ), $authorization_header ) 75 97 ) { 76 98 return new \WP_Error(
Note: See TracChangeset
for help on using the changeset viewer.