gpt4 book ai didi

google-oauth - 强制用户通过Google OAuth2选择帐户

转载 作者:行者123 更新时间:2023-12-03 23:53:08 32 4
gpt4 key购买 nike

我的应用程序中具有以下工作流程:


用户登录我的自定义应用
用户单击按钮以链接其YouTube帐户
应用程序使用下面的代码发出服务器端请求
用户被重定向到Google身份验证网址


此时,发生两件事之一:

[我永远不要这种行为]
-如果用户仅登录了一个Google帐户(即gmail,Google Apps for Domains等),则永远不会要求用户选择要链接的帐户。它只是假设他们要使用已登录的那个,然后继续进行。

[我一直想要这种行为]
-如果用户未登录任何Google帐户,或者他们登录了多个Google帐户,则系统会要求他们选择要继续使用的帐户。

问:即使用户当前已登录一个Google帐户,我是否可以通过一种方法来强迫用户选择一个帐户?

码:

private def getFlow() = {
if (flow == null) {
logger.info("Using OAuth client secrets file: " + GoogleOAuthService.CLIENT_SECRETS_JSON)
clientSecrets = GoogleClientSecrets.load(JacksonFactory.getDefaultInstance(),
new InputStreamReader(getClass.getResourceAsStream(GoogleOAuthService.CLIENT_SECRETS_JSON)));
redirectUri = clientSecrets.getDetails().getRedirectUris().get(0)
flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JacksonFactory.getDefaultInstance(), clientSecrets, SCOPES).setDataStoreFactory(
dataStoreFactory).setAccessType("offline").setApprovalPrompt("force").build()
}
flow
}

def newAuthorizationUrl(userId: String) = {
val urlRequest = getFlow().newAuthorizationUrl()

urlRequest.setAccessType("offline")
.setRedirectUri(redirectUri).setState(userId).build()
}

最佳答案

我认为您可以在url中添加一些参数,以告诉Google使用用户帐户显示同意屏幕,而不是假定使用默认的Google帐户。

这可以通过在URL中添加prompt=select_account+consent(URL编码的一部分添加“ +”)来完成。

到目前为止,我还没有尝试过,但是也许您可以尝试。

关于google-oauth - 强制用户通过Google OAuth2选择帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37711665/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com