Created
December 29, 2022 11:15
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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