Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
¿Cuál es el equivalente de auth.getIdTokenClient() en Android?

Necesito consultar un token de una función GCP, para eso, quiero hacer lo que hace la función js GoogleAuth<JSONClient>.getIdTokenClient(targetAudience) pero en Android.

En este momento estoy usando este código para generar un token de autenticación:

 GoogleCredentials .fromStream( app.assets.open("my_config_file.json") ) .createScoped( listOf( "https://www.googleapis.com/auth/cloud-platform" ) )

Pero el token generado es un ya29.c. , con el getIdToken obtengo un token válido.

¿Cómo puedo obtener un token válido como getIdToken en mi aplicación de Android?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para aplicaciones basadas en Java, tiene google-auth-library-java . Al buscar en los documentos de esta biblioteca, tiene las clases IdTokenCredentials.Builder e IdTokenCredentials .

También tienes un ejemplo de caso de uso:

 String credPath = "/path/to/svc_account.json"; String targetAudience = "https://example.com"; // For Application Default Credentials (as ServiceAccountCredentials) // export GOOGLE_APPLICATION_CREDENTIALS=/path/to/svc.json GoogleCredentials adcCreds = GoogleCredentials.getApplicationDefault(); if (!adcCreds instanceof IdTokenProvider) { // handle error message } IdTokenCredentials tokenCredential = IdTokenCredentials.newBuilder() .setIdTokenProvider(adcCreds) .setTargetAudience(targetAudience).build(); // Use the IdTokenCredential in an authorized transport GenericUrl genericUrl = new GenericUrl("https://example.com"); HttpCredentialsAdapter adapter = new HttpCredentialsAdapter(tokenCredential); HttpTransport transport = new NetHttpTransport(); HttpRequest request = transport.createRequestFactory(adapter).buildGetRequest(genericUrl); HttpResponse response = request.execute(); // Print the token, expiration and the audience System.out.println(tokenCredential.getIdToken().getTokenValue()); System.out.println(tokenCredential.getIdToken().getJsonWebSignature().getPayload().getAudienceAsList()); System.out.println(tokenCredential.getIdToken().getJsonWebSignature().getPayload().getExpirationTimeSeconds());
Documentación:
  • Repositorio Github
  • Uso de OAuth 2.0 con la biblioteca cliente API de Google para Java
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!