我的应用程序中有以下工作流程:
- 用户登录我的自定义应用程序
- 用户单击按钮以链接其 YouTube 帐户
- 应用程序使用下面的代码清单发出服务器端请求
- 用户被重定向到 google auth url
此时,会发生以下两种情况之一:
[我从不想要这种行为] - 如果用户只登录了一个 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()
}