如何在DotNetOpenAuth属性交换中使用FavoriteFlavor属性

时间:2010-12-15 12:30:44

标签: openid dotnetopenauth custom-attributes

This code显示了如何使用DotNetOpenAuth进行Attribute Exchange。

但是,如果我拥有自己的封闭式提供程序并希望使用自定义属性,例如FavoriteFlavor中定义的AcmeRequest属性作为DNOA样本的一部分,该怎么办?我如何处理DNOA使请求看起来像(但对于我的FavoriteFlavor请求):

openid.ns.ax=http://openid.net/srv/ax/1.0
openid.ax.mode=fetch_request
openid.ax.required=name,hackergotchi
openid.ax.if_available=email,web
openid.ax.type.name=http://axschema.org/namePerson
openid.ax.type.email=http://axschema.org/contact/email
openid.ax.type.hackergotchi=http://axschema.org/media/image/default
openid.ax.type.web=http://axschema.org/contact/web/default

http://blogs.gnome.org/jamesh/2007/11/26/openid-ax/中定义:

1 个答案:

答案 0 :(得分:2)

当您构建自己的OpenID提供程序时,我不确定您是否需要使OpenID请求看起来与此完全相同。

您只需要使用获取和存储(如果您想允许保存数据)请求和响应,这非常简单。

IAuthenticationRequest request)

var ax = new FetchRequest();
ax.Attributes.AddRequired("http://axschema.org/contact/email");
ax.Attributes.AddRequired("http://axschema.org/namePerson");

request.AddExtension(ax);

在OpendID提供程序上,您必须捕获此请求并创建FetchResponse

var fetchRequest = pendingRequest.GetExtension<FetchRequest>();

var fetchResponse = new FetchResponse();
fetchResponse.Attributes.Add("http://axschema.org/contact/email", "some@email.com");
fetchResponse.Attributes.Add("http://axschema.org/namePerson", "John");

pendingRequest.AddResponseExtension(fetchResponse);

请记住,这些只是Attribute Exchange扩展所需的一些额外步骤。