Last active
September 23, 2015 23:45
-
-
Save nonsintetic/af01e406732b923754b2 to your computer and use it in GitHub Desktop.
Fix for the WordPress plugin 'WP OAuth Server' to make it work with Rocket Chat's custom oAuth.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
This gist provides a fix for making the plugin WP oAuth Server work with | |
Rocket Chat's custom oAuth login. | |
Just require_once(file_name) this file in functions.php in your template | |
or just paste it at the end of it. | |
It's written for plugin version 3.1.7, but may work for newer ones as well. | |
Wordpress Plugin page: https://wordpress.org/plugins/oauth2-provider/ (made for v.3.1.7) | |
Rocket Chat: https://github.com/RocketChat/Rocket.Chat | |
More Details: https://github.com/RocketChat/Rocket.Chat/issues/747 | |
*/ | |
add_filter('wo_endpoints','wo_extend_resource_api', 2); | |
function wo_extend_resource_api ($methods) { | |
$methods['me'] = array('func'=>'_wo_rc'); | |
return $methods; | |
} | |
/** | |
* Replaces the default me enpoint with an exact copy of the one from v 3.1.7 + a fix for RocketChat. | |
* NOTE: If using a WP oAuth Server plugin version different to 3.1.7 you may want to check if this function | |
* has changed and just add the commented line after $me_data is first mentioned in the code. | |
* @param [type] $token [description] | |
* @return [type] [description] | |
*/ | |
function _wo_rc ( $token=null ) { | |
if (!isset($token['user_id']) || $token['user_id'] == 0) { | |
$response = new OAuth2\Response(); | |
$response->setError(400, 'invalid_request', 'Missing or invalid access token'); | |
$response->send(); | |
exit; | |
} | |
$user_id = &$token['user_id']; | |
global $wpdb; | |
$me_data = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}users WHERE ID=$user_id", ARRAY_A); | |
unset($me_data['user_pass']); | |
unset($me_data['user_activation_key']); | |
unset($me_data['user_url']); | |
$me_data['id'] = $me_data['ID']; //fix for Rocket Chat | |
$me_data['email'] = $me_data['user_email']; | |
$response = new OAuth2\Response($me_data); | |
$response->send(); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment