'; echo ''; } // add the login button add_action('login_form', 'bi_add_button'); function bi_add_button() { echo '

'; } // add 'browser_id_assertion' as wordpress query var add_filter('query_vars', 'bi_query_vars'); function bi_query_vars($vars) { $vars[] = 'browser_id_assertion'; return $vars; } // the verification code add_action('parse_request', 'bi_verify_id'); function bi_verify_id() { global $wp_query, $wp, $user; if( array_key_exists('browser_id_assertion', $wp->query_vars) ) { // some settings for the post request $args = array( 'method' => 'POST', 'timeout' => 30, 'redirection' => 0, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'assertion' => $wp->query_vars['browser_id_assertion'], // the assertion number we get from the js 'audience' => "http://".$_SERVER['HTTP_HOST'] // the server host ), 'cookies' => array(), 'sslverify' => 0 ); // check the response $response = wp_remote_post("https://browserid.org/verify", $args); if (!is_wp_error($response)) { $bi_response = json_decode($response['body'], true); // if everything is ok, check if there is a user with this email address if ($bi_response['status'] == 'okay') { $userdata = get_user_by('email', $bi_response['email']); if ($userdata) { $user = new WP_User($userdata->ID); wp_set_current_user($userdata->ID, $userdata->user_login); wp_set_auth_cookie($userdata->ID, $rememberme); do_action('wp_login', $userdata->user_login); // @todo: redirect to where you want } } } // @todo: redirect to an error page or to the login-page and add some error messages } }