sign in with wordpress

爷,独闯天下 提交于 2019-12-24 02:41:00

问题


Is there any WordPress login php script like this one?

This script is for signing in with WordPress.com account.

I have followed the documentation to write my script. But it did not provide me the access token when I print the access token. It shows it is null.
This is my code to implement sign in with WordPress.com account:

    session_start();
$client_id     = "2472";
$client_secret ="TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx";

$login_url     = "https://public-api.wordpress.com/oauth2/authorize?client_id=$client_id&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&response_type=code";

function getToken(){
    $curl = curl_init( "https://public-api.wordpress.com/oauth2/token" );
    curl_setopt( $curl, CURLOPT_POST, true );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
        'client_id'     => "2472",
        'redirect_uri'  => "http://w3.softwarecookerbd.com/wordpress.php",
        'client_secret' => "TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx",
        'code'          => $_GET['code'], // The code from the previous request
        'grant_type'    => 'authorization_code'
    ) );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
    $auth       = curl_exec( $curl );

    $secret     = json_decode($auth);

    echo "<pre>";
    var_dump($secret);
    exit;
    $access_key = $secret->access_token;

}

if(isset($_GET["code"])&&!empty($_GET["code"])){
    //$url = "https://public-api.wordpress.com/oauth2/token?client_id=$client_id&client_secret=client_secret&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&code=".$_GET['code']."&grant_type=authorization_code";
    //$response = file_get_contents($url);
    //echo $response;
    getToken();
}else{
    header("Location: ".$login_url);
}

回答1:


I am not sure about the actual script that you have posted , but there are several plugins that will allow you to do that , you might want to have a look at them, and since they are open-source , if you really want to do it yourself, you can always peep at the code and see what the problem is .

Some of them that I know (and not limited only to wordpress.com, but to other services as well) are :

http://wordpress.org/extend/plugins/oa-social-login/

http://wordpress.org/extend/plugins/socialauth-wp/

http://wordpress.org/extend/plugins/ssi-sumilux/screenshots/

And if I am not wrong (maybe i am ) also the wordpress jetpack has this feature ..

http://wordpress.org/extend/plugins/jetpack/



来源:https://stackoverflow.com/questions/15922794/sign-in-with-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!