使用带有 Java 的服务帐户访问云存储的 S3 API

问题描述

我想使用 Java AWS S3 API 访问我的 GCP Cloud Storage 存储桶以实现互操作性,因此不想在我的代码中使用 Google Api。在访问 Google Cloud Storage 时,我已经看到了使用 S3 API 进行基本身份验证的示例。我想通过我的服务帐户 json 密钥 ( OAuth 2 ) 进行身份验证,而不是为 Cloud Storage 创建另一个 HMAC 密钥。任何人都可以给我指出一个使用 Java 的例子。推荐的方法是什么 - 我认为 json oauth 2 身份验证是一个很好的方法

基本身份验证如下:

                // Create a BasicAWSCredentials using Cloud Storage HMAC credentials.
                BasicAWSCredentials googleCreds =
                    new BasicAWSCredentials(googleAccessKeyId,googleAccessKeySecret);

                // Create a new client and do the following:
                // 1. Change the endpoint URL to use the Google Cloud Storage XML API endpoint.
                // 2. Use Cloud Storage HMAC Credentials.
                AmazonS3 interopClient =
                    AmazonS3ClientBuilder.standard()
                        .withEndpointConfiguration(
                                new AwsClientBuilder.EndpointConfiguration("https://storage.googleapis.com","auto"))
                        .withCredentials(new AWsstaticCredentialsProvider(googleCreds))
                        .build();

但我想使用为服务帐户生成的 json 密钥进行身份验证。该服务帐号有权访问 Cloud Storage Viewer 和 Cloud Storage Creator。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)