- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想将 login_hint 附加到对 Google 的身份验证请求中。我正在使用以下代码:
FileDataStore fDS = new FileDataStore(Logger.Folder, true);
GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
clientSecrets.Secrets,
scopes.ToArray(),
username,
CancellationToken.None,
fDS).
Result;
var initializer = new Google.Apis.Services.BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
我在哪里传递这个参数以便在浏览器打开之前附加邮件地址?
最佳答案
感谢 Zhaph 的提示!
到目前为止我的解决方案:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Auth.OAuth2.Flows;
using Google.Apis.Auth.OAuth2.Requests;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MyOAuth2
{
//own implementation to append login_hint parameter to uri
public class MyOAuth2WebAuthorizationBroker : GoogleWebAuthorizationBroker
{
public new static async Task<UserCredential> AuthorizeAsync(ClientSecrets clientSecrets,
IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken,
IDataStore dataStore = null)
{
var initializer = new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = clientSecrets,
};
return await AuthorizeAsyncCore(initializer, scopes, user, taskCancellationToken, dataStore)
.ConfigureAwait(false);
}
private static async Task<UserCredential> AuthorizeAsyncCore(
GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<string> scopes, string user,
CancellationToken taskCancellationToken, IDataStore dataStore = null)
{
initializer.Scopes = scopes;
initializer.DataStore = dataStore ?? new FileDataStore(Folder);
var flow = new MyAuthorizationCodeFlow(initializer, user);
// Create an authorization code installed app instance and authorize the user.
return await new AuthorizationCodeInstalledApp(flow, new LocalServerCodeReceiver()).AuthorizeAsync
(user, taskCancellationToken).ConfigureAwait(false);
}
}
public class MyAuthorizationCodeFlow : GoogleAuthorizationCodeFlow
{
private readonly string userId;
/// <summary>Constructs a new Google authorization code flow.</summary>
public MyAuthorizationCodeFlow(Initializer initializer, string userId)
: base(initializer)
{
this.userId = userId;
}
public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
{
return new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
{
ClientId = ClientSecrets.ClientId,
Scope = string.Join(" ", Scopes),
//append user to url
LoginHint = userId,
RedirectUri = redirectUri
};
}
}
}
关于c# - 如何将 "&login_hint=user@gmail.com"附加到 GoogleWebAuthorizationBroker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27512300/
我正在学习 C#(为 Windows Phone 开发),并且我正在尝试对我的用户进行身份验证以进入 Google 的帐户。我正在使用这段代码: https://developers.google.c
我尝试使用 youtube api v3 和 .NET 将视频上传到 youtube,但它会永远挂起调用 AuthorizeAsync。您还可以在以下位置查看代码:https://developers
GoogleWebAuthorizationBroker.AuthorizeAsync() 在(农场,4.5 NET)暂存服务器上失败,但在本地服务器上运行良好。我已按照帮助热线上的每个代码进行操作,
我们的网站需要从后台代码(asp.net mvc 应用程序)上传视频到youtube。我正在尝试获取 google 凭据,但是当我调用 AuthorizeAsync 时,应用程序只是挂起。我到处寻找解
我有一个 C# .net Web 应用程序,用于将视频上传到 Youtube。这在大约 6 个月前有效,但现在已停止工作。当我在本地计算机上通过 Visual Studio 启动网站时,以下代码挂起:
我正在编写一个 C# 桌面应用程序,可以将其输出复制到用户的 Google 云端硬盘。但是,当我尝试使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 授
我正在尝试使用 Google Calendar API在我的非 MVC .NET Web 应用程序中。 (这似乎是一个重要的区别。) 我尝试使用来自 this example 的代码在谷歌和 this
我有一个使用 adsense api 的报告应用程序。 我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync 进行身份验证。 当我在本地使用它时,它工作正
我在将我的代码发布到 IIS7.0 后遇到 GoogleWebAuthorizationBroker.AuthorizeAsync 超时问题。 通过我的开发环境,一切都按预期工作。我看到了 Googl
我无法尝试从 MVC 应用程序访问特定的 Google 云端硬盘帐户。我所需要的只是让 MVC 网络应用程序访问我的谷歌驱动器扫描一些文件并根据谷歌驱动器的内容更改数据库。问题是在 IIS 中运行时,
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
服务器设置: ASP.NET 表单在 .net 4.5.1 集成管道上运行,在服务器 2012 上的 iis8 上运行。 我正在尝试从谷歌的 GoogleWebAuthorizationBroker
我想将 login_hint 附加到对 Google 的身份验证请求中。我正在使用以下代码: FileDataStore fDS = new FileDataStore(Logger.Folder,
当在 Windows 10 桌面/移动设备上运行时,此代码在我的 UWP 应用程序中运行良好,但在 Xbox One 上我收到错误: 我的 C# 代码: credential = await Goog
我在尝试让 MVC5 应用程序在部署时与 Google Mirror API(或与此相关的任何 Google API)一起工作时遇到了一个奇怪的问题。 这是我努力工作的代码: UserCredenti
我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 为 GoogleDrive 授权用户。 它适用于控制台或 UI 应用程序,但如果该方法在 Win
环境:.net 4.5.1 集成管道上的 ASP.NET 简单 Web 应用程序在服务器 2012 上的 iis8 上运行,不遵循 MVC。 我正在尝试从谷歌的 GoogleWebAuthorizat
我正在将 Google token 转换为 json 字符串格式并将该字符串存储在数据库中。 现在在谷歌驱动器中上传文件时,我想在 GoogleWebAuthorizationBroker.Autho
我遇到了与这个问题完全相同的问题: How do I set return_uri for GoogleWebAuthorizationBroker.AuthorizeAsync? 但是,这个问题在
我是一名优秀的程序员,十分优秀!