我正在使用 Google OAuth 2.0 对已安装的桌面 Java 应用程序进行身份验证。我正在使用 Google OAuth 2.0 Java 客户端库。
当我拨打电话请求用户授权访问他们的 Google 日历时,“请求权限”网页按预期显示在默认浏览器中。用户点击取消或接受后,网页显示消息:
收到验证码。关闭...
在 Internet Explorer 中,网页随即关闭。但是,在 Firefox 和 Chrome 中,网页仍然打开。
有没有办法强制关闭网页(从我的 Java 程序)?
这是我正在使用的触发网页的代码(取自 Google 开发人员的 CalendarSample(http://samples.google-api-java-client.googlecode.com/hg-history/425c5ffc30178f21aea592bc989849ea7e3498fe/calendar-cmdline-sample/instructions .html):
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
.build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");