【问题标题】:BigQuery Authentication ProblemsBigQuery 身份验证问题
【发布时间】:2017-01-01 18:31:23
【问题描述】:

我是 BigQuery 的初学者。 我的问题来自身份验证。 凭证文件已创建并存储在:

/home/ltloi/.config/gcloud/application_default_credentials.json

内容:

{
  "type": "service_account",
  "project_id": "xxx",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----xxx\n-----END PRIVATE KEY-----\n",
  "client_email": "xxx",
  "client_id": "xxx",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/bigqueryservices1%40neon-deployment-141106.iam.gserviceaccount.com"
}

源码:

// just authentication with google big query
 public static Bigquery createAuthorizedClient() throws IOException {
    // Create the credential
    HttpTransport transport = new NetHttpTransport();
    JsonFactory jsonFactory = new JacksonFactory();

    GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);

    // Depending on the environment that provides the default credentials (e.g. Compute Engine, App
    // Engine), the credentials may require us to specify the scopes we need explicitly.
    // Check for this case, and inject the Bigquery scope if required.
    if (credential.createScopedRequired()) {
      credential = credential.createScoped(BigqueryScopes.all());
    }

    return new Bigquery.Builder(transport, jsonFactory, credential)
        .setApplicationName("Bigquery Samples")
        .build();
  }

问题问题: 线程“主”java.io.IOException 中的异常:从位置读取凭据文件时出错

/home/ltloi/.config/gcloud/application_default_credentials.json

错误:

java.lang.RuntimeException:意外错误:java.security.InvalidAlgorithmParameterException:trustAnchors 参数必须为非空 在 com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getCredentialUsingWellKnownFile(DefaultCredentialProvider.java:251) 在 com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:117) 在 com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91) 在 com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) 在 com.google.cloud.bigquery.samples.GettingStarted.createAuthorizedClient(GettingStarted.java:53) 在 com.google.cloud.bigquery.samples.GettingStarted.main(GettingStarted.java:135)

当我尝试调试时,代码显示 HttpClient 附带 SSL 问题。

请高手帮忙解决。我尝试添加 SSL https://accounts.google.com/o/oauth2/auth

https://www.googleapis.com/oauth2/v1/certs

但无法解决。

我也安装了 Cloud SDK,但也无法解决。

{
  "client_id": "XXXX",
  "client_secret": "XXX",
  "refresh_token": "XXXX",
  "type": "authorized_user"
}

注意:我已完成 gcloud beta auth application-default login gcloud beta auth application-default print-access-token

感谢和问候,

【问题讨论】:

    标签: google-bigquery google-cloud-platform google-oauth


    【解决方案1】:

    是否使用以下命令创建了应用程序默认凭据?

    gcloud beta auth application-default login
    

    我认为您可以进行两个额外的快速测试来更接近问题根源。首先,您可以试试这个来验证您的凭据是否正常:

    gcloud beta auth application-default print-access-token
    

    然后,您可以复制并粘贴这个简短的 python 脚本来验证它是否有效(来自这里:https://cloud.google.com/bigquery/authentication

    # Grab the application's default credentials from the environment.
    credentials = GoogleCredentials.get_application_default()
    # Construct the service object for interacting with the BigQuery API.
    bigquery_service = build('bigquery', 'v2', credentials=credentials)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 2015-08-25
    • 2010-11-17
    • 2019-06-19
    • 2018-10-08
    相关资源
    最近更新 更多