如何在DotNetOpenAuth中为Google OpenId提供商指定弹出显示模式?

时间:2013-02-20 13:25:40

标签: dotnetopenauth

我有一个使用DotNetOpenAuth 3.5进行Google OpenId身份验证的ASP.NET应用程序。

我最近不得不将OpenId行为更改为窗口弹出窗口,以获得更流畅的UX体验。但是,弹出窗口会显示一个Google登录对话框,该对话框未针对弹出窗口进行优化。我意识到我必须以某种方式将ltmpl = popup参数添加到url https://accounts.google.com/ServiceLogin ?,但不知道如何。你能提供一些帮助吗?这是我正在使用的代码

string discoveryUri = "https://www.google.com/accounts/o8/id";
OpenIdRelyingParty openid = new OpenIdRelyingParty();
var b = new UriBuilder(context.Request.Url);
var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
req.AddExtension(fetchRequest);
req.RedirectToProvider();

1 个答案:

答案 0 :(得分:0)

我从来没有听说过你提到的这个ltmpl=popup参数,但是有一个OpenID UI扩展应该是RP在弹出窗口中与OP通信的方式。我已经在代码片段中添加了必要的行,并清理了其他一些内容。

var openid = new OpenIdRelyingParty();
var req = openid.CreateRequest(WellKnownProviders.Google);
var fetchRequest = new FetchRequest();
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
req.AddExtension(fetchRequest);
req.AddExtension(new UIRequest()); // inform the OP it's in a popup.
req.RedirectToProvider();

UIRequest扩展会在身份验证请求中添加openid.ui.mode=popup参数。