Przy okazji implementacji "Login with Facebook" postanowiłem, że za jednym zamachem dodam jeszce "Login with Google Account".
Po analizie dokumentacji oraz przykładów znalazłem kawałek kodu który pokazuje jasno i wyraźnie zasade działania.
<?php require_once("../config/init.php"); try { $openid = new LightOpenID; if(!$openid->mode) { $openid->identity = 'https://www.google.com/accounts/o8/id'; } } elseif($openid->mode == 'cancel') { } else { if($openid->validate()) { $identity = $openid->identity; $attributes = $openid->getAttributes(); $email = $attributes['contact/email']; $first_name = $attributes['namePerson/first']; $last_name = $attributes['namePerson/last']; } else { } } } catch(ErrorException $e) { } ?>
Lekko zmodyfikowany kod ze strony http://4rapiddev.com/php/php-login-or-sign...ount-by-openid/
Wszystko działa jak należy ale martwi mnie samo pobieranie danych. Google w odpowiedzi kieruje użytkownika pod adres podobny do tego: (dla ułatwienia rozbiłem na linijki)
Kod
http://127.0.0.1/~grzegorz/flexiCMS/oauth/google.php?login
&openid.ns=http://specs.openid.net/auth/2.0
&openid.mode=id_res
&openid.op_endpoint=https://www.google.com/accounts/o8/ud
&openid.response_nonce=2012-01-05T10:23:....
&openid.return_to=http://127.0.0.1/~grzegorz/flexiCMS/oauth/google.php?login
&openid.assoc_handle=...
&openid.signed=op_endpoint,claimed_id,identity,return_to,response_nonce,assoc
_handle,ns.ext1,ext1.mode,ext1.type.namePerson_first,ext1.value.namePerson_first,
ext1.type.contact_email,ext1.value.contact_email,ext1.type.namePerson_last,ext1.v
alue.namePerson_last
&openid.sig=...
&openid.identity=https://www.google.com/accounts/o8/id?id=...
&openid.claimed_id=https://www.google.com/accounts/o8/id?id=...
&openid.ns.ext1=http://openid.net/srv/ax/1.0
&openid.ext1.mode=fetch_response
&openid.ext1.type.namePerson_first=http://axschema.org/namePerson/first
&openid.ext1.value.namePerson_first=Jan
&openid.ext1.type.contact_email=http://axschema.org/contact/email
&openid.ext1.value.contact_email=exampleMail@gmail.com
&openid.ext1.type.namePerson_last=http://axschema.org/namePerson/last
&openid.ext1.value.namePerson_last=Kowalski
&openid.ns=http://specs.openid.net/auth/2.0
&openid.mode=id_res
&openid.op_endpoint=https://www.google.com/accounts/o8/ud
&openid.response_nonce=2012-01-05T10:23:....
&openid.return_to=http://127.0.0.1/~grzegorz/flexiCMS/oauth/google.php?login
&openid.assoc_handle=...
&openid.signed=op_endpoint,claimed_id,identity,return_to,response_nonce,assoc
_handle,ns.ext1,ext1.mode,ext1.type.namePerson_first,ext1.value.namePerson_first,
ext1.type.contact_email,ext1.value.contact_email,ext1.type.namePerson_last,ext1.v
alue.namePerson_last
&openid.sig=...
&openid.identity=https://www.google.com/accounts/o8/id?id=...
&openid.claimed_id=https://www.google.com/accounts/o8/id?id=...
&openid.ns.ext1=http://openid.net/srv/ax/1.0
&openid.ext1.mode=fetch_response
&openid.ext1.type.namePerson_first=http://axschema.org/namePerson/first
&openid.ext1.value.namePerson_first=Jan
&openid.ext1.type.contact_email=http://axschema.org/contact/email
&openid.ext1.value.contact_email=exampleMail@gmail.com
&openid.ext1.type.namePerson_last=http://axschema.org/namePerson/last
&openid.ext1.value.namePerson_last=Kowalski
Jak widać dane o które prosiłem (imie, naziwsko, mail) są dostarczone call-backiem. W przypadku facebook dostaje w odpowiedzi klucz którego używam do poberania bezpośrednio danych.
W przypadku przekazania ich url'em istnieje bardzo duże prawdopodobieństwo, że ktoś najzwyczajniej w świecie podrobi taki adres i zaloguje się do webaplikacji.
W adresi obecne są tekże rozmaite klucze jednakże nie doszukałem się czy mogę w jakiś sposób zweryfikować, czy owe rządanie rzeczywiście wygenerował serwer Google czy też ktoś podrobił adres.
Jakieś pomysły koledzy?
