简体   繁体   English

雅虎开放id登录api

[英]Yahoo open id login api

Im new to open id, but still i have tried to integrate the open id in my website. 我是新的开放ID,但我仍然试图在我的网站中集成开放的ID。 Im using yahoo provider to login in to my website. 我正在使用雅虎提供商登录我的网站。 Could any help me in getting the user information like yahoo mail id , first name , last name. 可以帮助我获取用户信息,如雅虎邮件ID,名字,姓氏。

I have take the below code from a website which is provided for google, i have changed the provider to yahoo 我从谷歌提供的网站上获取以下代码,我已将提供商更改为雅虎

Code which i have tried: 我试过的代码:

<?php
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
# Change 'localhost' to your domain name.
$openid = new LightOpenID('localhost');
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://me.yahoo.com';
header('Location: ' . $openid->authUrl());
}
?>
<form action="?login" method="post">
<button>Login with Yahoo</button>
</form>
<?php
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
print_r($openid->ax_to_sreg);
}
} catch(ErrorException $e) {
echo $e->getMessage();
}

After loggin im getting out put like this : loggin后出来就像这样:

User https://open.login.yahooapis.com/openidx20/user_profile/XXXX has logged in.

what is the use of above url? 上面的url有什么用? How can i fetch the user information? 我如何获取用户信息?

After googling a lot find my solution. 经过谷歌搜索后找到我的解决方案。 Now im able to fetch the email of logged in user 现在我能够获取登录用户的电子邮件

Here is the modified code : 这是修改后的代码:

<?php


require 'openid.php';

try
{
    # Change 'localhost' to your domain name.
    $openid = new LightOpenID($_SERVER['HTTP_HOST']);

    //Not already logged in
    if(!$openid->mode)
    {

        //do the login
        if(isset($_GET['login']))
        {
            //The google openid url
            $openid->identity = 'https://me.yahoo.com';

            //Get additional google account information about the user , name , email , country
            $openid->required = array('contact/email' , 'namePerson/first' , 'namePerson/last' , 'pref/language' , 'contact/country/home');

            //start discovery
            header('Location: ' . $openid->authUrl());
        }
        else
        {
            //print the login form
            login_form();
        }

    }

    else if($openid->mode == 'cancel')
    {
        echo 'User has canceled authentication!';
        //redirect back to login page ??
    }

    //Echo login information by default
    else
    {
        if($openid->validate())
        {
            //User logged in
            $d = $openid->getAttributes();

            $first_name = $d['namePerson/first'];
            $last_name = $d['namePerson/last'];
            $email = $d['contact/email'];
            $language_code = $d['pref/language'];
            $country_code = $d['contact/country/home'];

            $data = array(
                'first_name' => $first_name ,
                'last_name' => $last_name ,
                'email' => $email ,
            );

            //now signup/login the user.
            print_r($data);
        }
        else
        {
            //user is not logged in
        }
    }
}

catch(ErrorException $e)
{
    echo $e->getMessage();
}

/*
    This function will print the login form with the button
*/
function login_form()
{
?>
<a href="?login">Login with Yahoo</a>
<?php
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM