Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating old GoogleCredential object to new GoogleCredentials object for OAuth #1386

Open
z0mg opened this issue Apr 25, 2024 · 1 comment

Comments

@z0mg
Copy link

z0mg commented Apr 25, 2024

I have a web application and obtain an auth code with which I get a refresh token. I then supply this refresh token to the library and it can obtain a new access code before I access it.

This is how I currently do it for the old version:

import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.services.bigquery.Bigquery;

    public static final HttpTransport httpTransport = new NetHttpTransport();
    public static final JsonFactory jsonFactory = new JacksonFactory();

    GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
        .setJsonFactory(jsonFactory)
        .setClientSecrets("client_id", "secret")
        .build()
        .setFromTokenResponse(new TokenResponse().setRefreshToken("refresh_token");

    credential.refreshToken();

    Bigquery bigquery = new Bigquery.Builder(httpTransport, jsonFactory, credential)
        .setApplicationName("appName").build();

And I would like to build the equivalent with a GoogleCredentials object, which the newer BigQuery library needs - how to do this?

    com.google.auth.oauth2.GoogleCredentials credentials = ??? ;

    import com.google.cloud.bigquery.BigQuery bigquery =
        BigQueryOptions.newBuilder()
            .setCredentials(credentials)
            .setProjectId(projectId)
            .build()
            .getService();
@dungtt
Copy link

dungtt commented May 5, 2024

Same question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants