首页 > 解决方案 > 始终提示用户在应用程序启动时选择一个帐户

问题描述

我正在使用代码示例中的代码在应用程序启动时对用户进行身份验证。

UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { YouTubeService.Scope.Youtube },
        "user",
        CancellationToken.None,
        new FileDataStore(this.GetType().ToString())
    );
}

var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = this.GetType().ToString()
});

一切正常,除了我想每次都强制显示“选择帐户”屏幕(现在它只显示第一次,然后记住用户),因为应用程序应该允许不同的用户登录。

看起来我应该将prompt请求参数设置为 select_account,但我不知道我应该怎么做,AuthorizeAsync方法不接受任何额外的参数。

标签: c#youtube-apigoogle-oauthgoogle-api-dotnet-client

解决方案


您是对的,目前无法以简单的方式做到这一点。

我已经提交了一个错误来解决这个问题:https ://github.com/googleapis/google-api-dotnet-client/issues/1322


推荐阅读