在浏览器控件中打开 OAuth2 授权 URL
Opening OAuth2 Authorization URL in a browser control
我正在编写一个小程序,试图了解 Google 的驱动器 API。我正在使用 GoogleWebAuthorizationBroker class 要求用户授予应用程序权限,但缺点是它会在 Chrome 中自动打开一个新的浏览器选项卡(例如):
const string ApplicationName = "TestApp";
string[] scopes = { DriveService.Scope.Drive };
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
我想知道是否有办法获取 AuthorizationURL,以便我可以使用它显示浏览器对话框,从而获取相应的令牌。
如何做到这一点?提前致谢。
目前客户端库的编写方式会在默认浏览器中自动打开。
已经有针对此功能的问题请求。 GoogleWebAuthorizationBroker in embedded browser? #547
回答:目前无法获得授权url,您可以自行播种对话。客户端库是一个开源项目,因此您可以添加它。
我正在编写一个小程序,试图了解 Google 的驱动器 API。我正在使用 GoogleWebAuthorizationBroker class 要求用户授予应用程序权限,但缺点是它会在 Chrome 中自动打开一个新的浏览器选项卡(例如):
const string ApplicationName = "TestApp";
string[] scopes = { DriveService.Scope.Drive };
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
我想知道是否有办法获取 AuthorizationURL,以便我可以使用它显示浏览器对话框,从而获取相应的令牌。
如何做到这一点?提前致谢。
目前客户端库的编写方式会在默认浏览器中自动打开。
已经有针对此功能的问题请求。 GoogleWebAuthorizationBroker in embedded browser? #547
回答:目前无法获得授权url,您可以自行播种对话。客户端库是一个开源项目,因此您可以添加它。