2010-07-05 7 views
8

Mam problemy z małą biblioteką OpenID o nazwie LightOpenID . Potrafię uwierzytelniać się u prawie wszystkich dostawców, ale nie wiem, jak pobrać dane od dostawcy. Dostaję tylko Array(), eaven z print_r().PHP: LightOpenID, jak pobrać dane konta od dostawcy?

+1

Potrzebujemy więcej informacji na temat ... jak mówi nam dokładnie to, czego próbowałem (jak w, skopiuj i wklej kod) oraz następnie podaj nam wyniki (jak w, kopiuj i wklej). – Narcissus

+0

Przepraszamy, oto kod: http://pastebin.com/kS9S4WVk Wszystko działa całkiem nieźle, ale na linii 39-41 próbuję wydrukować wiadomość e-mail z bieżącym kontem. Wynikiem jest "Array()". – Pwntus

+0

Czy są zgłaszane błędy błędów wyświetlania? Czy sprawdziłeś swój log błędów PHP? – Narcissus

Odpowiedz

8

Musisz zadzwonić pod numer getAttributes()po$openid->validate() wcześniej.

Pamiętaj:

Należy pamiętać, że to nie gwarantuje, że każdy z wymaganych parametrów/opcja będzie obecny

+0

Zrobiłem to teraz: http://pastebin.com/ULsLvhxp Aby wyświetlić wiadomość e-mail, czy używam $ foo ['email']? – Pwntus

+0

Będzie to '$ foo ['kontakt/email']' - zgodnie z dokumentami atrybuty są mapowane do formatu AX. – Pete

+2

Również, '$ openid-> required = array ('contact/email');' musi być wywołane ** przed ** '$ openid-> validate()' – Pete

2

To jak go używać. To jest plik openid.php w folderze lightopenid. W klasie wprowadzić następujące dodatkowe funkcje -

class LightOpenID 
{ 
    public $returnUrl 
     , $required = array() 
     , $optional = array() 
     , $verify_peer = null 
     , $capath = null 
     , $cainfo = null; 

    // these are the variables which store the data about the user... 
    public function ret_fname() { return $this->data['openid_ext1_value_namePerson_first']; } 
    public function ret_lname() { return $this->data['openid_ext1_value_namePerson_last']; } 
    public function ret_email() { return $this->data['openid_ext1_value_contact_email']; } 
    public function ret_lang() { return $this->data['openid_ext1_value_pref_language']; } 
} 



teraz dokonać przykładowy login.php plików, które nazywa się kiedy chcesz uwierzytelnić. Nie może być kilka kopii tego pliku na różnych domenach uwierzytelniania itp

<?php 
# Logging in with Google accounts requires setting special identity, so this example shows how to do it. 
session_start(); 
require 'lightopenid/openid.php'; 
include_once('config.php');    // initial setting file 

try { 

    $openid = new LightOpenID;       // akshat - declared an object of class lightopenid.. this is listed in openid.php 
    if(!$openid->mode) { 

     if(isset($_GET['login'])) { 

      $openid->identity = 'https://www.google.com/accounts/o8/site-xrds?hd=YourDomain.in'; //this can be changed as you know...  

      $openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); // akshat - line added by me from after reading from the net.... 

      header('Location: ' . $openid->authUrl());  
     } 
?> 
<script type="text/javascript" src="js/jquery-1.4.2.min.js" language="javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
      document.form.submit(); 
    }); 

</script> 
<form name="form" action="?login" method="post"> </form> 
<?php 
    } elseif($openid->mode == 'cancel') { 
     echo 'User has canceled authentication for Your Domain !'; 
    } else {            // FETCH USER INFO HERE 
       $fname = $openid->ret_fname();    // fetching user first name... 
     $lname = $openid->ret_lname();     // fetching user last name... 
     $email = $openid->ret_email();     // fetching user email... 
     $lang = $openid->ret_lang();     // fetching user language... 
       session_start(); 

       // use it as required. I set them in session ! 
       $_SESSION['admin']['emailID'] = $email;   //put email id in session. 
       $_SESSION['admin']['fname'] = $fname;   //put first name also in session. 
       $_SESSION['admin']['lname'] = $lname;   //put last name also in session. 
       $rurl = $_SESSION['redirect'];     // you can ignore this. Go to your own page now... 
       header("Location:$rurl");    // Go back to the calling application ! 

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