OpenId - 如何使用 checkid_immediate 和 x-has-session?
文档没有详细介绍这两个参数。我知道它们在某种程度上与登录状态检查有关。
我想检查用户当前是否已登录浏览器(意思是,使用谷歌登录,并选中“保持登录状态”)
我希望能够区分以下状态:
用户是登录浏览器(即使用 Google 登录 例如,并选中“让我保持登录状态”)并且该用户已经 批准了我的应用程序。
任何其他状态。 (用户未登录。用户已登录,但使用 他尚未批准的身份...等等)
如果我知道我处于第一个状态,我不需要“显示”弹出窗口(我给它顶部= 9999 左侧= 9999)
我试图弄清楚用这段代码找出两种状态。这需要在没有任何用户交互或任何视觉提示的情况下完成。
public partial class WebForm1 : System.Web.UI.Page
{
protected string Url { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
var parameters = new Dictionary<string, string>();
parameters.Add("openid.ns", "http://specs.openid.net/auth/2.0");
parameters.Add("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select");
parameters.Add("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select");
parameters.Add("openid.return_to", "http://localhost:17556/redirect.aspx");
parameters.Add("openid.realm", "http://localhost:17556/");
parameters.Add("openid.mode", "checkid_immediate");
parameters.Add("openid.ns.ax", "http://openid.net/srv/ax/1.0");
parameters.Add("openid.ax.mode", "fetch_request");
parameters.Add("openid.ax.type.email", "http://axschema.org/contact/email");
parameters.Add("openid.ax.required", "email");
parameters.Add("openid.ns.ui", "http://specs.openid.net/extensions/ui/1.0");
parameters.Add("openid.ui.mode", "x-has-session");
string OpenIdEndpoint = https://www.google.com/accounts/o8/ud;
var url = CreateUrlRequest(OpenIdEndpoint, parameters);
WebClient wc = new WebClient();
var res = wc.UploadString(url, "");
}
public string CreateUrlRequest(string i_Url, Dictionary<string, string> i_Parameters)
{
return string.Format("{0}?{1}", i_Url, string.Join("&", i_Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value)).ToList()));
}
}
运行此代码,回调将发送到redirect.aspx,但查询字符串没有有关我感兴趣的状态的任何信息。它包含 openid.mode=setup_needed 等内容。
The documentation doesn't tell much about those two parameters. I understand they somehow related to log in status checking.
I want to check if a user is currently logged in the browser (Meaning, signed in with google, and checked "keep me logged in" )
I want to be able to differentiate between to states :
A user is logged in the browser (meaning, signed in with Google for
example, and check "Keep me logged in") and that user already
approved my app.Any other state. (user is not logged in . user logged in but with an
identity he didn't approved yet... etc.)
If I know I am in the first state, I don't need to "show" the popup (I give it top=9999 left=9999)
I am trying to figure out the two states with this code. This needs to be done without any user interaction or any visual cue.
public partial class WebForm1 : System.Web.UI.Page
{
protected string Url { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
var parameters = new Dictionary<string, string>();
parameters.Add("openid.ns", "http://specs.openid.net/auth/2.0");
parameters.Add("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select");
parameters.Add("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select");
parameters.Add("openid.return_to", "http://localhost:17556/redirect.aspx");
parameters.Add("openid.realm", "http://localhost:17556/");
parameters.Add("openid.mode", "checkid_immediate");
parameters.Add("openid.ns.ax", "http://openid.net/srv/ax/1.0");
parameters.Add("openid.ax.mode", "fetch_request");
parameters.Add("openid.ax.type.email", "http://axschema.org/contact/email");
parameters.Add("openid.ax.required", "email");
parameters.Add("openid.ns.ui", "http://specs.openid.net/extensions/ui/1.0");
parameters.Add("openid.ui.mode", "x-has-session");
string OpenIdEndpoint = https://www.google.com/accounts/o8/ud;
var url = CreateUrlRequest(OpenIdEndpoint, parameters);
WebClient wc = new WebClient();
var res = wc.UploadString(url, "");
}
public string CreateUrlRequest(string i_Url, Dictionary<string, string> i_Parameters)
{
return string.Format("{0}?{1}", i_Url, string.Join("&", i_Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value)).ToList()));
}
}
running this code, a callback is sent to redirect.aspx, but the query string doesn't have any information about the states I am interested in. It contains openid.mode=setup_needed among other things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论