Pobierz atrybuty OpenID AX z Google / Yahoo in Rails
Używam wtyczki railsopen_id_authentication w mojej aplikacji. Działa to dla MyOpenID, jednak uwierzytelnianie w Google nie może uzyskać adresu e-mail jako części wymaganych atrybutów.
Z tego, co rozumiem, Google ignoruje żądania atrybutów sreg i tylko nasłuchuje schematu AX dla adresu e-mail.
Oto mój kod:
def open_id_authentication(openid_url)
#google only responds to AX for email, so we must provide that also
authenticate_with_open_id(openid_url, :required => [:nickname, :email, 'http://axschema.org/contact/email']) do |result, identity_url, registration|
if result.successful?
@user = User.find_or_initialize_by_identity_url(identity_url)
if @user.new_record?
unless registration['email'] || registration['http://axschema.org/contact/email']
failed_login "Your OpenID provider didn't send us an email address."
return
end
#some providers (like Google) won't send a nick name. We'll use email instead for those
nick = registration['nickname']
nick |= registration['email']
nick |= registration['http://axschema.org/contact/email']
email = registration['email'];
email |= registration['http://axschema.org/contact/email']
@user.login = nick
@user.email = email
@user.save(false)
end
self.current_user = @user
successful_login
else
failed_login result.message
end
end
Rozumiem, że przesyłam adres e-mail (zarówno sreg, jak i AX) jakowymagany i powinienem być w stanie wyciągnąć je zregistration
przykład, który jest przekazywany wraz z odpowiedzią.
Kiedy loguję się do Google, adres e-mail jest przekazywany z powrotem jako „t”.
Czy obchodzę się z tym nieprawidłowo? Jak mogę uzyskać adres e-mail użytkownika z Google? Czy będę musiał przeskakiwać przez inne obręcze, aby wspierać Yahoo?