重定向google oauth2.0localhost:9696/callback 在实时tomcat服务器上

svujldwt  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(251)

我正在JavaSpringBoot中实现GoogleDrive api v3。应用程序在我的本地机器上运行良好。我在tomcat中部署了这个应用程序,它运行在我们的uat服务器上进行测试。我按照程序授权我的谷歌驱动器api我得到了同意窗口。我选择了访问api所需的所有权限,并单击了“允许”按钮,但之后它立即将我重定向到https://localhost:9696/返回url,该url提供找不到页面的信息。我被困在这里了。我需要提供我的域而不是默认的localhost有回调url吗?

private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
// Load client secrets.
InputStream in = GoogleDriveService.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, SCOPES)
                    .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                    .setAccessType("offline").build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(9696).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

Implementation Ref. API Doc:-
https://developers.google.com/drive/api/v3/quickstart/java?hl=en&authuser=2

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题