我有以下代碼:DotNetOpenAuth和谷歌
protected void Page_Load(object sender, EventArgs e)
{
var openId = new OpenIdRelyingParty();
HttpContext httpContext = HttpContext.Current;
var headers = new WebHeaderCollection();
foreach (string header in httpContext.Request.Headers)
{
headers.Add(header, httpContext.Request.Headers[header]);
}
string requestUrl = string.Format("http://localhost:12345/Login/{0}",
httpContext.Request.Url.Query);
var requestInfo = new HttpRequestInfo(httpContext.Request.HttpMethod,
new Uri(requestUrl),
httpContext.Request.RawUrl, headers,
httpContext.Request.InputStream);
var response = openId.GetResponse(requestInfo);
if (response != null)
{
ClaimsResponse claimResponse = response.GetExtension<ClaimsResponse>();
lblUser.Text = claimResponse.FullName;
if (response.Exception != null)
{
lblError.Text = response.Exception.Message;
}
}
}
protected void btnTest_Click(object sender, EventArgs e)
{
try
{
using (OpenIdRelyingParty openId = new OpenIdRelyingParty())
{
string identifier = @"https://www.google.com/accounts/o8/id";
var request = openId.CreateRequest(identifier,
new Realm("http://localhost:12345/"),
new Uri("http://localhost:12345/Login/"));
request.AddExtension(new ClaimsRequest
{
Email = DemandLevel.Require
});
request.RedirectToProvider();
}
}
catch (Exception ex)
{
// TODO: log exception
throw;
}
}
當我執行的代碼,用戶進行身份驗證,但ClaimsResponse爲空。
代碼適用於MyOpenId。
任何幫助,將不勝感激。
這個問題是其他幾個問題的重複。在發佈新問題之前,請搜索http://stackoverflow.com/search?q=claimsresponse。 – 2010-08-02 13:23:13
我在發佈這個問題之前使用了搜索。 ClaimsReposnse僅在與Google合作時才返回null。在其他主題中,ClaimsReposnse始終爲空。 – 2010-08-02 13:59:56
這不是唯一的。有些人只是將它視爲「始終爲空」,即使它們只用Google進行測試。 – 2010-08-02 14:15:23