使用OpenID的谷歌友好名称?
当我和谷歌OpenID提供商打乒乓球时,我不能得到一个友好的名字/昵称/用户名(不管你怎么称呼它) 我得到了一些可怕的东西,如下所示:使用OpenID的谷歌友好名称?,openid,dotnetopenauth,Openid,Dotnetopenauth,当我和谷歌OpenID提供商打乒乓球时,我不能得到一个友好的名字/昵称/用户名(不管你怎么称呼它) 我得到了一些可怕的东西,如下所示: www.google.com/accounts/o8/id?id=AItOawmtAnQvSXGhRTkAHZWyxi4L4EKa7xoTT1dk 而不是像这样的好东西 JohnDoe 以友好的方式从Google获取用户名的协议是什么,比如说myopenid **我使用的是DotNetOpenAuth*你不能。OP发布的标识符严格取决于OP。RP实际上没
www.google.com/accounts/o8/id?id=AItOawmtAnQvSXGhRTkAHZWyxi4L4EKa7xoTT1dk
而不是像这样的好东西
JohnDoe
以友好的方式从Google获取用户名的协议是什么,比如说myopenid
**我使用的是DotNetOpenAuth*你不能。OP发布的标识符严格取决于OP。RP实际上没有任何发言权。现在,一些OPs支持在登录时提供属性,如昵称、电子邮件地址等。谷歌对这些属性的支持非常有限,只提供电子邮件地址 谷歌选择不发布用户可识别标识符,因为这是一种信息泄露风险。雅虎通过向用户提供人性友好和非人性友好的标识符,用户可以在两者之间进行选择。MyOpenID和其他OP通常只使用用户在OP注册时选择的用户友好标识符 您可能希望在RP处使用特殊情况下的Google,以便在用户登录时选择一个更友好的字符串显示给用户,或者由于Google不是唯一这样做的,因此编写代码以确定标识符何时不可读,并显示对用户更友好的内容,以便用户知道他们已登录(可能是他们的电子邮件地址或他们在你的网站上取的昵称)
注意事项:如果您选择显示比谷歌发布的标识符更友好的标识符,您必须使用谷歌官方声明的标识符作为用户的官方用户名,并传递给
进行身份验证。重定向自登录
和在数据库中查找用户名。任何您放在一起的se通常会带来安全风险。从2012年起,似乎支持通过属性交换协议检索名字和姓氏。下面是一些使用web框架和Janrain软件包的Python代码示例
来自openid.consumer导入consumer
从openid.extensions.ax导入AttrInfo、FetchRequest、FetchResponse
从openid.store.filestore导入文件openidstore
从openid.store.sqlstore导入PostgreSQLStore、MySQLStore、SQLiteStore
AX_FIRSTNAME=http://axschema.org/namePerson/first'
AX_LASTNAME=http://axschema.org/namePerson/last'
AX_电子邮件地址:http://axschema.org/contact/email'
@查看\u配置(路由\u name='openID\u start',权限=无需权限)
def启动(请求):
“启动openID身份验证过程”
params=request.params
openIDURL=params.get('openIDURL')
如果不是openIDURL:
返回HTTPResponse('需要参数:openIDURL')
openIDConsumer=get_consumer(请求)
尝试:
openIDRequest=openIDConsumer.begin(openIDURL)
除consumer.DiscoveryFailure外,错误:
返回HTTPResponse('发现失败:%s'%escape(错误))
其他:
如果未打开IDRequest:
返回HTTPResponse('不是openID提供程序:%s'%escape(openIDURL))
axRequest=FetchRequest()
add(AttrInfo(AX_FIRSTNAME,required=True))
add(AttrInfo(AX_LASTNAME,required=True))
axRequest.add(AttrInfo(AX_EMAIL,required=True))
openIDRequest.addExtension(axRequest)
sourceURL=request.host\u url
targetURL=request.route\u url('openID\u finish')
如果openIDRequest.shouldSendRedirect():
返回HTTPFound(location=openIDRequest.redirectURL(sourceURL,targetURL))
返回HTTPResponse(openIDRequest.htmlMarkup(sourceURL,targetURL))
@查看配置(route\u name='openID\u finish',权限=无需权限)
def完成(请求):
'完成openID身份验证过程'
openIDConsumer=get_consumer(请求)
targetURL=request.route\u url('openID\u finish')
openIDResponse=openIDConsumer.complete(request.params,targetURL)
html=openIDResponse.status+'
'
对于键,openIDResponse.\uuuu dict\uuuu.iteritems()中的值:
html+='%s:%s
'%(转义(键),转义(值))
html+='
'
如果consumer.SUCCESS==openIDResponse.status:
axResponse=FetchResponse.fromSuccessResponse(openIDResponse)
html+='名字:%s
'%escape(axResponse.get(AX_FIRSTNAME))
html+='姓氏:%s
'%escape(axResponse.get(AX_LASTNAME))
html+='电子邮件:%s
'%escape(axResponse.get(AX_电子邮件))
返回HTTPResponse(html)
def get_消费者(请求):
尝试:
openIDStore={
“sqlite”:SQLiteStore,
“postgresql”:PostgreSQLStore,
“mysql”:MySQLStore,
}[db.bind.name](db.bind.raw_connection())
除KeyError外:
openIDStore=FileOpenIDStore('data/openIDs'))
尝试:
openIDStore.createTables()
除:
通过
返回consumer.consumer(request.session,openIDStore)
基于Roy的回答,我尝试使用DotNetOpenAuth
发出相同的请求,效果很好。
请求:
var req = openid.CreateRequest("https://www.google.com/accounts/o8/id");
var fetch = new FetchRequest();
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Contact.Email,true));
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.First,true));
fetch.Attributes.Add(new AttributeRequest(WellKnownAttributes.Name.Last,true));
req.AddExtension(fetch);
注意:确保AttributeRequest
构造函数的第二个参数设置为true
响应部分是直接的。
var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
var fetch = response.GetExtension<FetchResponse>();
if (fetch != null) {
IList<string> emailAddresses =fetch.Attributes[WellKnownAttributes.Contact.Email].Values;
IList<string> firstNames = fetch.Attributes[WellKnownAttributes.Name.First].Values;
IList<string> lastName = fetch.Attributes[WellKnownAttributes.Name.Last].Values;
}
var openid=new OpenIdRelyingParty();
var response=openid.GetResponse();
var fetch=response.GetExtension();
if(fetch!=null){
IList emailAddresses=fetch.Attributes[WellKnownAttributes.Contact.Email].Values;
IList firstNames=fetch.Attributes[WellKnownAttributes.Name.First].Values;
IList lastName=fetch.Attributes[WellKnownAttributes.Name.Last].Values;
}
谢谢你澄清这一点。我想在用户的电子邮件中使用默认的友好标识符是可行的。你会知道其他哪些服务在友好名称方面做得不好吗?雅虎是我唯一知道的另一家,而且它有时也会有这种行为。安德鲁,我设法深入到你的博客文章中,发现e带rega的一个
var openid = new OpenIdRelyingParty();
var response = openid.GetResponse();
var fetch = response.GetExtension<FetchResponse>();
if (fetch != null) {
IList<string> emailAddresses =fetch.Attributes[WellKnownAttributes.Contact.Email].Values;
IList<string> firstNames = fetch.Attributes[WellKnownAttributes.Name.First].Values;
IList<string> lastName = fetch.Attributes[WellKnownAttributes.Name.Last].Values;
}