set_endpoint( 'request_token', 'https://api.login.yahoo.com/oauth/v2/get_request_token', 'GET' ); $this->set_endpoint( 'authorize', 'https://api.login.yahoo.com/oauth/v2/request_auth', 'GET' ); $this->set_endpoint( 'access_token', 'https://api.login.yahoo.com/oauth/v2/get_token', 'POST' ); $creds = $this->get_credentials(); $this->app_id = $creds['app_id']; $this->key = $creds['key']; $this->secret = $creds['secret']; $this->consumer = new OAuthConsumer( $this->key, $this->secret, $this->callback_url ); $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1; } function basic_ui_intro() { echo '

' . sprintf( __( 'To connect to Yahoo!, you need to Create a new project. Make sure you set the Access Scope to This app requires access to private user data. When you select that, you will be asked for an Application Domain, which should probably be set to http://%2$s. Which APIs you request access for will depend on how Keyring will be used on this site. Common ones will be Contacts, Social Directory, Status, and Updates.', 'keyring' ), 'https://developer.apps.yahoo.com/dashboard/createKey.html', $_SERVER['HTTP_HOST'] ) . '

'; echo '

' . __( "Once you've created your project, copy and paste your Consumer key and Consumer secret (from under the Authentication Information: OAuth section of your app's details) into the boxes below. You don't need an App ID for Yahoo!.", 'keyring' ) . '

'; } function parse_response( $response ) { return json_decode( $response ); } function build_token_meta( $token ) { $expires = isset( $token['oauth_expires_in'] ) ? gmdate( 'Y-m-d H:i:s', time() + $token['oauth_expires_in'] ) : 0; $this->set_token( new Keyring_Access_Token( 'yahoo', new OAuthToken( $token['oauth_token'], $token['oauth_token_secret'] ) ) ); // Get user profile information $response = $this->request( "http://social.yahooapis.com/v1/user/{$token['xoauth_yahoo_guid']}/profile?format=json" ); if ( Keyring_Util::is_error( $response ) ) { $meta = array(); } else { $this->person = $response->profile; $meta = array( 'user_id' => $token['xoauth_yahoo_guid'], 'name' => $this->person->nickname, 'picture' => $this->person->image->imageUrl, ); } return apply_filters( 'keyring_access_token_meta', $meta, 'yahoo', $token, $response, $this ); } function get_display( Keyring_Access_Token$token ) { return $token->get_meta( 'name' ); } function test_connection() { $this->maybe_refresh_token(); $guid = $this->token->get_meta( 'external_id' ); $res = $this->request( 'http://social.yahooapis.com/v1/user/' . $guid . '/profile?format=json' ); if ( !Keyring_Util::is_error( $res ) ) return true; return $res; } function maybe_refresh_token() { global $wpdb; if ( empty( $this->token->token ) || empty( $this->token->token->tokenExpires ) ) return; if ( $this->token->token->tokenExpires && $this->token->token->tokenExpires < time() ) { $api_url = 'https://api.login.yahoo.com/oauth/v2/get_token'; $api_url .= '?oauth_session_handle=' . $this->token->token->sessionHandle; $refresh = $this->request( $api_url, array( 'method' => 'GET', 'raw_response' => true, ) ); if ( !Keyring_Util::is_error( $refresh ) ) { $token = $this->parse_access_token( $refresh ); // Fake request token global $keyring_request_token; $keyring_request_token = new Keyring_Request_Token( $this->get_name(), array() ); // Build (real) access token $access_token = new Keyring_Access_Token( $this->get_name(), new OAuthToken( $token['oauth_token'], $token['oauth_token_secret'] ), $this->build_token_meta( $token ), $this->token->unique_id ); // Store the updated access token $access_token = apply_filters( 'keyring_access_token', $access_token, $token ); $id = $this->store->update( $access_token ); // And switch to using it $this->set_token( $access_token ); } } } } add_action( 'keyring_load_services', array( 'Keyring_Service_Yahoo', 'init' ) );