【发布时间】:2021-07-05 22:22:48
【问题描述】:
我正在尝试从 WCF 服务调用 OAuth2.0 api 以检索 accessToken。 我设法使用下面的代码调用了 Azure 中的 OAuth2.0 API:
// Create confidential client application
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(oAuthAuthenticationConfig.ClientId)
.WithClientSecret(oAuthAuthenticationConfig.ClientSecret)
.WithAuthority(new Uri(oAuthAuthenticationConfig.Authority))
.Build();
string[] scopes = new string[] { $"{oAuthAuthenticationConfig.ApiUrl}" };
result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
不,我不确定如何将其用于 Google 中的 OAuth2.0 API。 ConfidentialClientApplicationBuilder.Create(CliendId) 作为参数的客户端 ID 必须是有效的 GUID,而我从 Google OAuth 应用程序生成的客户端 ID 类似于
const string clientID = "879017285009-4igdmblu7i6b7djetijvjhc5p1h7v2ul.apps.googleusercontent.com";
我什至可以将 nuget Microsoft.Identity.Client 中定义的 ConfidentialClientApplicationBuilder 用于 Google/第三方 OAuth2.0 提供程序吗?如果不是,我的其他选择是什么?
【问题讨论】:
标签: azure oauth-2.0 google-oauth