Skip to content

Instantly share code, notes, and snippets.

@jraska
Created December 29, 2022 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jraska/ebc7b3a665ff36c18cb4e89dcb6f9018 to your computer and use it in GitHub Desktop.
Save jraska/ebc7b3a665ff36c18cb4e89dcb6f9018 to your computer and use it in GitHub Desktop.
Simple console app verifying the client app integrity token with Play API: https://developer.android.com/google/play/integrity/verdict#decrypt-verify
// https://developer.android.com/google/play/integrity/verdict#decrypt-verify
// implementation 'com.google.api-client:google-api-client:1.32.2'
// implementation 'com.google.apis:google-api-services-playintegrity:v1-rev20220211-1.32.1'
package com.jraska.github.client.identity.integrity
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport
import com.google.api.client.json.gson.GsonFactory
import com.google.api.services.playintegrity.v1.PlayIntegrity
import com.google.api.services.playintegrity.v1.PlayIntegrityScopes
import com.google.api.services.playintegrity.v1.model.DecodeIntegrityTokenRequest
import java.io.File
import java.io.FileInputStream
fun main(args: Array<String>) {
val token = args[0]
val jsonCredentialsFilePath = args[1]
if (!File(jsonCredentialsFilePath).exists()) {
throw IllegalArgumentException("Credentials JSON was not found on path: '$jsonCredentialsFilePath'")
}
val playIntegrity = playIntegrity(jsonCredentialsFilePath)
val tokenRequest = DecodeIntegrityTokenRequest()
tokenRequest.integrityToken = token
val response = playIntegrity.v1()
.decodeIntegrityToken("com.jraska.github.client", tokenRequest)
.execute()
println(response)
}
private fun playIntegrity(credentialsFilePath: String): PlayIntegrity {
val credentials = GoogleCredential.fromStream(FileInputStream(credentialsFilePath))
.createScoped(listOf(PlayIntegrityScopes.PLAYINTEGRITY))
return PlayIntegrity.Builder(
GoogleNetHttpTransport.newTrustedTransport(),
GsonFactory.getDefaultInstance(),
credentials
).setApplicationName("github-client-integrity-verifier").build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment