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

Migrate to Version Catalog (+Bump Deps) #71

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
uses: gradle/wrapper-validation-action@v3

- uses: gradle/gradle-build-action@v2
- uses: gradle/gradle-build-action@v3

- name: Build and run tests
run: ./gradlew build
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Release
run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }}
run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }}

on:
workflow_dispatch:
Expand Down Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1

- uses: gradle/gradle-build-action@v2
- uses: gradle/gradle-build-action@v3
with:
# Disable writing to cache. Don't want to spoil the main cache
cache-read-only: true
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
rm gradle.properties.bak

- name: GitHub Release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
tag_name: v${{ inputs.version }}
21 changes: 12 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
buildscript {
ext {
compose_ui_version = '1.4.0'
compose_ui_version = '1.5.0'
}
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.2.2' apply false
id 'com.android.library' version '8.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
id 'org.jetbrains.dokka' version '1.9.10' apply false
id 'com.vanniktech.maven.publish' version "0.25.1" apply false
alias libs.plugins.androidApplication apply false
alias libs.plugins.androidLibrary apply false
alias libs.plugins.kotlinAndroid apply false
alias libs.plugins.dokka apply false
alias libs.plugins.mavenPublish apply false

id 'com.diffplug.spotless' version "6.19.0"
alias libs.plugins.spotless
}

subprojects {
apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
target("src/**/*.kt")
targetExclude("$buildDir/**/*")
targetExclude("bin/**/*")
ktlint()
.editorConfigOverride([
'ktlint_standard_property-naming': 'disabled',
'ktlint_function_naming_ignore_when_annotated_with': 'Composable'
])
}
}
}
6 changes: 3 additions & 3 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
implementation(libs.core.ktx)
implementation(libs.kotlinx.coroutines)

testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
testImplementation(libs.kotlinx.coroutines.test)
}
26 changes: 13 additions & 13 deletions dev-app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
alias libs.plugins.androidApplication
alias libs.plugins.kotlinAndroid
}

apply from: rootProject.file("$rootDir/common.gradle")
Expand Down Expand Up @@ -32,7 +32,7 @@ android {
}

composeOptions {
kotlinCompilerExtensionVersion '1.5.5'
kotlinCompilerExtensionVersion '1.5.12'
}

lint {
Expand All @@ -43,17 +43,17 @@ android {
dependencies {
implementation project(path: ':sdk')

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation(libs.androidx.appcompat)
implementation(libs.androidx.lifecycle)

implementation 'androidx.activity:activity-compose:1.7.0'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.4.0'
implementation platform(libs.compose.bom)
implementation(libs.compose.activity)
implementation(libs.compose.ui)
implementation(libs.compose.tooling)
implementation(libs.compose.material)

implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation(libs.okhttp.core)

debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
debugImplementation(libs.compose.tooling)
debugImplementation(libs.compose.test.manifest)
}
90 changes: 44 additions & 46 deletions dev-app/src/main/java/com/uid2/dev/network/AppUID2Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,56 +50,54 @@ class AppUID2Client(
* address, or telephone number.
*/
@Throws(AppUID2ClientException::class)
suspend fun generateIdentity(
requestString: String,
type: RequestType,
): UID2Identity? = withContext(Dispatchers.IO) {
// Check to make sure we have a valid endpoint to hit.
val url = apiGenerateUrl ?: throw AppUID2ClientException(ERROR_UNKNOWN_API)

// Check that the key and secret were provided.
if (key.isEmpty() || secret.isEmpty()) {
throw AppUID2ClientException(ERROR_NO_SECRET_OR_KEY)
}
suspend fun generateIdentity(requestString: String, type: RequestType): UID2Identity? =
withContext(Dispatchers.IO) {
// Check to make sure we have a valid endpoint to hit.
val url = apiGenerateUrl ?: throw AppUID2ClientException(ERROR_UNKNOWN_API)

// Check that the key and secret were provided.
if (key.isEmpty() || secret.isEmpty()) {
throw AppUID2ClientException(ERROR_NO_SECRET_OR_KEY)
}

// The secret should be Base64 encoded. Let's decode it and verify that what we have appears valid.
val secretBytes = runCatching { Base64.decode(secret, Base64.DEFAULT) }.getOrNull()
?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECODE_SECRET)

// The request will contain an encrypted payload which contains the verified identity of the user.
val requestBody = encryptRequest(
secretBytes,
mapOf(type.parameter to requestString),
) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_ENCRYPT_REQUEST)

val request = Request.Builder()
.url(url)
.addHeader(REQUEST_HEADER_AUTHORIZATION, REQUEST_HEADER_BEARER + key)
.addHeader(REQUEST_HEADER_CONTENT_TYPE, REQUEST_HEADER_TEXT_PLAIN)
.post(requestBody.toRequestBody())
.build()

// Make the request and verify that it was successful.
val response = client.newCall(request).execute()
if (!response.isSuccessful) {
throw AppUID2ClientException(ERROR_REQUEST_FAILED + response.code)
}
// The secret should be Base64 encoded. Let's decode it and verify that what we have appears valid.
val secretBytes = runCatching { Base64.decode(secret, Base64.DEFAULT) }.getOrNull()
?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECODE_SECRET)

// The request will contain an encrypted payload which contains the verified identity of the user.
val requestBody = encryptRequest(
secretBytes,
mapOf(type.parameter to requestString),
) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_ENCRYPT_REQUEST)

val request = Request.Builder()
.url(url)
.addHeader(REQUEST_HEADER_AUTHORIZATION, REQUEST_HEADER_BEARER + key)
.addHeader(REQUEST_HEADER_CONTENT_TYPE, REQUEST_HEADER_TEXT_PLAIN)
.post(requestBody.toRequestBody())
.build()

// Make the request and verify that it was successful.
val response = client.newCall(request).execute()
if (!response.isSuccessful) {
throw AppUID2ClientException(ERROR_REQUEST_FAILED + response.code)
}

// If we have a valid response, we can try to decrypt it.
val responseBody = decryptResponse(
secret,
response.body?.string()
?: throw AppUID2ClientException(ERROR_RESPONSE_NO_BODY),
) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECRYPT_RESPONSE)
// If we have a valid response, we can try to decrypt it.
val responseBody = decryptResponse(
secret,
response.body?.string()
?: throw AppUID2ClientException(ERROR_RESPONSE_NO_BODY),
) ?: throw AppUID2ClientException(ERROR_UNABLE_TO_DECRYPT_RESPONSE)

// Now try to parse the decrypted response (as JSON).
val responseToken = runCatching {
GenerateTokenResponse.fromJson(JSONObject(responseBody))
}.getOrNull() ?: throw AppUID2ClientException(ERROR_UNABLE_TO_PARSE_RESPONSE)
// Now try to parse the decrypted response (as JSON).
val responseToken = runCatching {
GenerateTokenResponse.fromJson(JSONObject(responseBody))
}.getOrNull() ?: throw AppUID2ClientException(ERROR_UNABLE_TO_PARSE_RESPONSE)

// After all that, we should finally have a valid UID2Identity!
return@withContext responseToken.body
}
// After all that, we should finally have a valid UID2Identity!
return@withContext responseToken.body
}

private fun encryptRequest(key: ByteArray, params: Map<String, String>): ByteArray? {
// The body of the payload is expected to be the following:
Expand Down
5 changes: 3 additions & 2 deletions dev-app/src/main/java/com/uid2/dev/ui/views/EmailInputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowForward
import androidx.compose.material.icons.Icons.AutoMirrored.Filled
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material.icons.filled.Email
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -50,7 +51,7 @@ fun EmailInputView(modifier: Modifier, onEmailEntered: (String) -> Unit) {
backgroundColor = MaterialTheme.colors.primary,
) {
Icon(
imageVector = Icons.Default.ArrowForward,
imageVector = Filled.ArrowForward,
contentDescription = stringResource(R.string.email_submit_content_description),
tint = Color.White,
)
Expand Down
53 changes: 53 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[versions]
agp = "8.3.2"
kotlin = "1.9.23"
core-ktx = "1.13.0"
junit = "4.13.2"
appcompat = "1.6.1"
coroutines-version = "1.8.0"
compose = "1.9.0"
compose-bom = "2024.04.01"
compose-tooling = "1.6.6"
gma = "23.0.0"
ima = "3.33.0"

[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
kotlinx-coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version = "1.8.0" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-lifecycle = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-ktx", version = "2.7.0" }

# Compose
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
compose-activity = { group = "androidx.activity", name = "activity-compose", version.ref = "compose" }
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose-tooling" }
compose-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "compose-tooling" }
compose-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest", version.ref = "compose-tooling"}
compose-material = { group = "androidx.compose.material", name = "material", version = "1.6.6" }

# OkHttp
okhttp-core = { group = "com.squareup.okhttp3", name = "okhttp", version = "4.12.0" }

# GMA / IMA
gma-ads = { group = "com.google.android.gms", name = "play-services-ads", version.ref = "gma" }
ima-ads = { group = "com.google.ads.interactivemedia.v3", name = "interactivemedia", version.ref = "ima" }
androidx-multidex = { group = "androidx.multidex", name = "multidex", version = "2.0.1" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "2.1.4" }
androidx-media = { group = "androidx.media", name = "media", version = "1.7.0" }
androidx-browser = { group = "androidx.browser", name = "browser", version = "1.8.0" }
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version = "1.9.0" }

# Testing
junit = { group = "junit", name = "junit", version.ref = "junit" }
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutines-version" }
json = { group = "org.json", name = "json", version = "20240303" }
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version = "4.1.0" }
mockito-inline = { group = "org.mockito", name = "mockito-inline", version = "4.8.0" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" }
kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version = "6.25.0" }
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Mar 13 14:21:49 GMT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading