使用FetchData DotNetOpenAuth?FetchData、DotNetOpenAuth

2023-09-07 15:48:31 作者:づ男人要霸气

我已实施的这里描述的这种简单的code 的(VS 2010,web表单)

I have implemented this simple code as described here ( vs 2010 , webforms)

protected void Page_Load(object sender, EventArgs e)
{
  var openid = new OpenIdRelyingParty();
  var response = openid.GetResponse();

  if (response != null && response.Status == AuthenticationStatus.Authenticated)
  {
    FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
  }
}

点击功能:

protected void btnGoogle_Click(object sender, ImageClickEventArgs e)
{
  using (OpenIdRelyingParty openid = new OpenIdRelyingParty())
  {
    var request = openid.CreateRequest("https://www.google.com/accounts/o8/id");
    request.RedirectToProvider();
  }
}

问题1

当我点击登录(通过谷歌)它打开本同意屏幕:

When I click the login ( via google) it opens this consent screen :

但怎么来的工作原理的?我想,我必须创建一个的的API密钥的在谷歌开发者控制台为了让人们登录。 (像我一样在这里与MYNE的其他应用程序 - > 的)

But how come it works ? I thought that I have to create an API key in Google developer console in order to allow people to login. ( like I did here with other app of myne->)

很显然,我没有创造的任意的本地主机应用程序。它是如何仍然有效? (这又是一个演示中,我已经从互联网上下载)。

Obviously I didn't create any "localhost" app. so how does it still works ? (again it's a demo I've downloaded from the internet).

问题#2

在我有结果:

我如何可以获取用户的数据? (电子邮件为例)的 {文章并没有提到它} 的

How can I fetch user data ? ( email for example) {the article doesn't mention it}

NB DotNetOpenAuth版本3.4.6.10357 的

推荐答案

这行的工作,因为它使用 OpenID的并没有OAuth2。打开ID是之前 Oauth2 的老同学。

That line works because it uses openId and not OAuth2. Open id is old school before Oauth2.

您也应该了解:

重要提示:谷歌有pcated的OpenID 2.0代$ P $,将向下关闭它   后迁移的时期。如果你的应用程序使用的OpenID 2.0的用户信息   端点,或2.0的OAuth登录(早期版本),你应该迁移   在迁移时间表给出的最后期限应用程序。

Important: Google has deprecated OpenID 2.0 and will shut it down after a migration period. If your app uses OpenID 2.0, the userinfo endpoint, or OAuth 2.0 login (early version), you should migrate your app by the deadlines given in the migration timetable.

由于的OpenID已经二〇一五年四月二十零日前被撤销preciated,将被关闭我不会推荐它发展。

Because OpenId has been depreciated and will be shutdown before April 20, 2015 I wouldn't recommend developing with it.

要回答这个问题,该请求不需要客户端ID,因为它的打开而不是Oauth2只oauth2需要一个客户端ID。

To answer the question that request doesn't require a client id because its opened and not Oauth2 only oauth2 requires a client id.

推荐:谷歌的API客户端库 教程:谷歌Oauth2 C#