-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b75959
commit 296b147
Showing
5 changed files
with
73 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
51 changes: 51 additions & 0 deletions
51
...src/main/java/com/stripe/android/financialconnections/features/consent/verifyIntegrity.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.stripe.android.financialconnections.features.consent | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.OutputStreamWriter | ||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
import java.net.URLEncoder | ||
|
||
|
||
suspend fun verifyIntegrity(integrityToken: String, packageName: String) = withContext(Dispatchers.IO) { | ||
val url = URL("https://attestation-android.glitch.me/verify-integrity") | ||
val connection = url.openConnection() as HttpURLConnection | ||
connection.requestMethod = "POST" | ||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") | ||
connection.setRequestProperty("Accept", "application/json") | ||
connection.doOutput = true | ||
connection.connectTimeout = 15000 | ||
connection.readTimeout = 15000 | ||
|
||
// Constructing URL-encoded form data | ||
val requestBody = "integrityToken=${URLEncoder.encode(integrityToken, "UTF-8")}" + | ||
"&packageName=${URLEncoder.encode(packageName, "UTF-8")}" | ||
|
||
println("Request Payload: $requestBody") // Log the URL-encoded form data | ||
|
||
connection.outputStream.use { os -> | ||
OutputStreamWriter(os, "UTF-8").use { writer -> | ||
writer.write(requestBody) | ||
writer.flush() | ||
} | ||
} | ||
|
||
val responseCode = connection.responseCode | ||
val responseMessage: String | ||
|
||
if (responseCode == HttpURLConnection.HTTP_OK) { | ||
responseMessage = connection.inputStream.bufferedReader().use { it.readText() } | ||
} else { | ||
responseMessage = connection.errorStream?.bufferedReader()?.use { | ||
it.readText() | ||
} ?: "Error occurred with response code: $responseCode" | ||
println("Error response code: $responseCode - $responseMessage") | ||
} | ||
|
||
connection.disconnect() | ||
|
||
println("Response Message: $responseMessage") | ||
|
||
responseMessage | ||
} |
This file contains 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