如何在 .NET Framework 2.0 网站中验证 Google 用户的 ID 令牌?
How can I authenticate Google user's ID token in a .NET framework 2.0 website?
我已经在客户端成功实现了 Google 登录。我的下一步是在后端验证用户的 ID 令牌。
根据 this guide, it is recommended that I use the Google API Client Library. However, my company is creating the website using .NET framework 2.0, which is not currently supported (v1.9.2) 的建议。
运行 Install-Package Google.Apis
在我的程序包管理器控制台中出现以下错误:
Install-Package : Could not install package 'Microsoft.Bcl 1.1.10'. You are trying to install this package into a project that targets '.NETFramework, Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework.
我有哪些选择?是否有其他方法可以验证 ID 令牌或使用 Google API 客户端库?
简单的回答是你不能。 Google .net 客户端库的当前版本仅支持 .net Framework 4.0 和 4.5。您要么必须使用它,要么自己编写代码。
Oauth2 和所有 API 请求都是简单的 HTTP posts 和 HTTP GETS,因此从头开始编写代码并不像您想的那么难。使用.Net Framework 2.0。
第 1 步请求身份验证:(HTTP GET)
https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code
步骤 2 授权应用程序 (HTTP POST)
https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code
步骤 3 刷新 Refreshtoke (HTTP post)
https://accounts.google.com/o/oauth2/token
client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token=1/ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA&grant_type=refresh_token
代码从 Google 3 legged oauth2 流程教程中截取。
我已经在客户端成功实现了 Google 登录。我的下一步是在后端验证用户的 ID 令牌。
根据 this guide, it is recommended that I use the Google API Client Library. However, my company is creating the website using .NET framework 2.0, which is not currently supported (v1.9.2) 的建议。
运行 Install-Package Google.Apis
在我的程序包管理器控制台中出现以下错误:
Install-Package : Could not install package 'Microsoft.Bcl 1.1.10'. You are trying to install this package into a project that targets '.NETFramework, Version=v2.0', but the package does not contain any assembly references or content files that are compatible with that framework.
我有哪些选择?是否有其他方法可以验证 ID 令牌或使用 Google API 客户端库?
简单的回答是你不能。 Google .net 客户端库的当前版本仅支持 .net Framework 4.0 和 4.5。您要么必须使用它,要么自己编写代码。
Oauth2 和所有 API 请求都是简单的 HTTP posts 和 HTTP GETS,因此从头开始编写代码并不像您想的那么难。使用.Net Framework 2.0。
第 1 步请求身份验证:(HTTP GET)
https://accounts.google.com/o/oauth2/auth?client_id={clientid}.apps.googleusercontent.com&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code
步骤 2 授权应用程序 (HTTP POST)
https://accounts.google.com/o/oauth2/token code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code
步骤 3 刷新 Refreshtoke (HTTP post)
https://accounts.google.com/o/oauth2/token client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token=1/ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA&grant_type=refresh_token
代码从 Google 3 legged oauth2 流程教程中截取。