我的应用程序中有以下工作流程:
此时,发生以下两种情况之一:
[我从不想要这种行为] - 如果用户只登录了一个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中添加prompt=select_account+consent
(“+”作为url编码的一部分添加)来完成。
直到现在我都没试过,但也许你可以试试。
在第一条评论中,@ Hans给出了类似主题的正确链接。但是,如果它没有帮助,那么这里是解决方案:
只需在请求谷歌网址时添加&prompt=consent
参数。