Yahoo Open ID Iniciar sesión API
-
21-12-2019 - |
Pregunta
Soy nuevo para abrir ID, pero aún así lo he intentado integrar la ID ABIERTE en mi sitio web.Estoy usando el proveedor de Yahoo para iniciar sesión en mi sitio web.Podría ayudarme a obtener la información del usuario como el ID de correo de Yahoo, el nombre, el apellido.
He tomado el siguiente código de un sitio web que se proporciona para Google, he cambiado al proveedor a Yahoo
Código que he intentado:
<?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();
}
Después de iniciar sesión, estoy saliendo así:
User https://open.login.yahooapis.com/openidx20/user_profile/XXXX has logged in.
¿Cuál es el uso de la URL anterior?¿Cómo puedo buscar la información del usuario?
Solución
Después de buscar a Google, encontrar mi solución.Ahora soy capaz de buscar el correo electrónico de usuario registrado
Aquí está el código modificado:
<?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
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow