From 91d734fd8ec2709b920a838c0c15037ec7e4dab1 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 14:39:14 -0600 Subject: [PATCH 1/6] Refactor gradle build file to kotlin --- .../firebase-authexchange.gradle | 54 ------------------- .../firebase-authexchange.gradle.kts | 53 ++++++++++++++++++ 2 files changed, 53 insertions(+), 54 deletions(-) delete mode 100644 firebase-authexchange/firebase-authexchange.gradle create mode 100644 firebase-authexchange/firebase-authexchange.gradle.kts diff --git a/firebase-authexchange/firebase-authexchange.gradle b/firebase-authexchange/firebase-authexchange.gradle deleted file mode 100644 index ade4db1e247..00000000000 --- a/firebase-authexchange/firebase-authexchange.gradle +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2022 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -plugins { - id 'firebase-library' - id 'kotlin-android' -} - -firebaseLibrary { - publishSources = true -} - -android { - compileSdkVersion project.targetSdkVersion - defaultConfig { - targetSdkVersion project.targetSdkVersion - minSdkVersion 16 - versionName version - multiDexEnabled true - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - testOptions { - unitTests { - includeAndroidResources = true - } - } -} - -dependencies { - implementation project(':firebase-common') - implementation project(':firebase-common:ktx') - implementation project(':firebase-components') - implementation project(':firebase-authexchange-interop') - - implementation 'androidx.annotation:annotation:1.5.0' - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion" - - testImplementation 'androidx.test:core:1.5.0' - testImplementation "com.google.truth:truth:$googleTruthVersion" - testImplementation 'junit:junit:4.13.2' - testImplementation "org.robolectric:robolectric:$robolectricVersion" -} diff --git a/firebase-authexchange/firebase-authexchange.gradle.kts b/firebase-authexchange/firebase-authexchange.gradle.kts new file mode 100644 index 00000000000..2579fdaecbe --- /dev/null +++ b/firebase-authexchange/firebase-authexchange.gradle.kts @@ -0,0 +1,53 @@ +plugins { + id("firebase-library") + kotlin("android") + kotlin("plugin.serialization") version "1.7.20" +} + +firebaseLibrary { + publishSources = true +} + +android { + val targetSdkVersion : Int by rootProject + + compileSdk = targetSdkVersion + defaultConfig { + minSdk = 16 + targetSdk = targetSdkVersion + multiDexEnabled = true + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + sourceSets { + getByName("main") { + java.srcDirs("src/main/kotlin") + } + getByName("test") { + java.srcDirs("src/test/kotlin") + } + } + + testOptions.unitTests.isIncludeAndroidResources = true +} + +dependencies { + val googleTruthVersion: String by rootProject + val kotlinVersion: String by rootProject + val robolectricVersion: String by rootProject + + implementation(project(":firebase-common")) + implementation(project(":firebase-common:ktx")) + implementation(project(":firebase-components")) + implementation(project(":firebase-authexchange-interop")) + + implementation("androidx.annotation:annotation:1.5.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + + + testImplementation("androidx.test:core:1.5.0") + testImplementation("com.google.truth:truth:$googleTruthVersion") + testImplementation("junit:junit:4.13.2") + testImplementation("org.robolectric:robolectric:$robolectricVersion") +} From 7fa1d26deb0d4fe5723da25125b94e5551e75b72 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 14:39:51 -0600 Subject: [PATCH 2/6] Implement route defs for backend --- .../firebase/authexchange/network/Routes.kt | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt diff --git a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt new file mode 100644 index 00000000000..22831767555 --- /dev/null +++ b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt @@ -0,0 +1,103 @@ +package com.google.firebase.authexchange.network + +import kotlinx.serialization.Serializable + +/** + * Defines what an HTTP request may look like when interacting with the backend API for + * [FirebaseAuthExchange][com.google.firebase.authexchange.FirebaseAuthExchange]. + */ +@Serializable internal sealed interface Request + +/** Defines what an HTTP response may look like when submitting a [Request]. */ +@Serializable internal sealed interface Response + +/** + * OIDC Credential. + * + * Useful for apps with external login already set-up, otherwise known as a headless OIDC flow. + * + * While this isn't the only OIDC flow that the API supports, it's the only flow that the mobile SDK + * supports- so there is no base class for credentials. + * + * @property idToken JWT encoded OIDC token returned from a third party provider + */ +@Serializable internal data class ImplicitCredentialsP(val idToken: String) + +/** + * Auth Token that can be used to access certain Firebase Services. + * + * This is merely the proto type for the network layer, and is completely separate from the user + * facing [AuthExchangeToken][com.google.firebase.authexchange.AuthExchangeToken]. + * + * @property accessToken signed JWT containing claims that identify a user + * @property ttl the duration from the time this token is minted until its expiration + */ +@Serializable internal data class AuthExchangeTokenP(val accessToken: String, val ttl: String) + +/** + * Request header for the `/ExchangeCustomInstallationAuthToken` endpoint. + * + * @see ExchangeTokenResponseP + * + * @property token relative resource name of the audience project and location + * @property installationAuthToken the installation token issued to the app + */ +@Serializable +internal data class ExchangeCustomInstallationAuthTokenRequestP( + val token: String, + val installationAuthToken: String +) : Request + +/** + * Request header for the `/ExchangeCustomToken` endpoint. + * + * @see ExchangeTokenResponseP + * + * @property token relative resource name of the audience project and location + * @property customToken a custom JWT token signed with the developer's credentials + */ +@Serializable +internal data class ExchangeCustomTokenRequestP(val token: String, val customToken: String) : + Request + +/** + * Request header for the `/ExchangeOidcToken` endpoint. + * + * @see ExchangeOidcTokenResponseP + * + * @property token relative resource name of the audience project and location + * @property providerId the display name or id of the OIDC provider + * @property implicitCredentials JWT token from the OIDC provider, provided by the developer + */ +@Serializable +internal data class ExchangeOidcTokenRequestP( + val token: String, + val providerId: String, + val implicitCredentials: ImplicitCredentialsP +) : Request + +/** + * Response header for endpoints that just expect an [AuthExchangeTokenP]. + * + * @see ExchangeCustomTokenRequestP + * @see ExchangeCustomInstallationAuthTokenRequestP + * + * @property token auth token returned by the backend + */ +@Serializable internal data class ExchangeTokenResponseP(val token: AuthExchangeTokenP) : Response + +/** + * Response header for the `/ExchangeOidcToken` endpoint. + * + * @see ExchangeOidcTokenRequestP + * + * @property authExchangeToken auth token returned by the backend + * @property oidcIdToken OAuth id token received from the OIDC provider + * @property oidcRefreshToken optional OAuth refresh token received from the OIDC provider + */ +@Serializable +internal data class ExchangeOidcTokenResponseP( + val authExchangeToken: AuthExchangeTokenP, + val oidcIdToken: String, + val oidcRefreshToken: String? = null +) : Response From ea496395a369e1a74d683c1b9d5c69ffd411cf5c Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 14:56:37 -0600 Subject: [PATCH 3/6] Fixed type in InstallationToken naming --- .../com/google/firebase/authexchange/network/Routes.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt index 22831767555..dff1e7eb6e1 100644 --- a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt +++ b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt @@ -35,7 +35,7 @@ import kotlinx.serialization.Serializable @Serializable internal data class AuthExchangeTokenP(val accessToken: String, val ttl: String) /** - * Request header for the `/ExchangeCustomInstallationAuthToken` endpoint. + * Request header for the `/ExchangeInstallationAuthToken` endpoint. * * @see ExchangeTokenResponseP * @@ -43,7 +43,7 @@ import kotlinx.serialization.Serializable * @property installationAuthToken the installation token issued to the app */ @Serializable -internal data class ExchangeCustomInstallationAuthTokenRequestP( +internal data class ExchangeInstallationAuthTokenRequestP( val token: String, val installationAuthToken: String ) : Request @@ -80,7 +80,7 @@ internal data class ExchangeOidcTokenRequestP( * Response header for endpoints that just expect an [AuthExchangeTokenP]. * * @see ExchangeCustomTokenRequestP - * @see ExchangeCustomInstallationAuthTokenRequestP + * @see ExchangeInstallationAuthTokenRequestP * * @property token auth token returned by the backend */ From 6c5b9021d3c5c79f32d88879f318d9d9ac926c31 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 23:44:40 -0600 Subject: [PATCH 4/6] Replaced explicit versioning with version catalog --- .../firebase-authexchange.gradle.kts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/firebase-authexchange/firebase-authexchange.gradle.kts b/firebase-authexchange/firebase-authexchange.gradle.kts index 2579fdaecbe..2057b3fa683 100644 --- a/firebase-authexchange/firebase-authexchange.gradle.kts +++ b/firebase-authexchange/firebase-authexchange.gradle.kts @@ -32,22 +32,18 @@ android { } dependencies { - val googleTruthVersion: String by rootProject - val kotlinVersion: String by rootProject - val robolectricVersion: String by rootProject - implementation(project(":firebase-common")) implementation(project(":firebase-common:ktx")) implementation(project(":firebase-components")) implementation(project(":firebase-authexchange-interop")) - implementation("androidx.annotation:annotation:1.5.0") + implementation(libs.androidx.annotation) implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") + implementation(libs.kotlin.stdlib) - testImplementation("androidx.test:core:1.5.0") - testImplementation("com.google.truth:truth:$googleTruthVersion") - testImplementation("junit:junit:4.13.2") - testImplementation("org.robolectric:robolectric:$robolectricVersion") + testImplementation(libs.androidx.test.core) + testImplementation(libs.truth) + testImplementation(libs.junit) + testImplementation(libs.robolectric) } From 74e6fb795b0ca2d2a1a784ac78d5dd63a3b58572 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 23:45:30 -0600 Subject: [PATCH 5/6] Removed verbose info & refactored ttl to be more readable --- .../google/firebase/authexchange/network/Routes.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt index dff1e7eb6e1..c7ce909eec3 100644 --- a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt +++ b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt @@ -1,5 +1,6 @@ package com.google.firebase.authexchange.network +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable /** @@ -16,9 +17,6 @@ import kotlinx.serialization.Serializable * * Useful for apps with external login already set-up, otherwise known as a headless OIDC flow. * - * While this isn't the only OIDC flow that the API supports, it's the only flow that the mobile SDK - * supports- so there is no base class for credentials. - * * @property idToken JWT encoded OIDC token returned from a third party provider */ @Serializable internal data class ImplicitCredentialsP(val idToken: String) @@ -30,9 +28,13 @@ import kotlinx.serialization.Serializable * facing [AuthExchangeToken][com.google.firebase.authexchange.AuthExchangeToken]. * * @property accessToken signed JWT containing claims that identify a user - * @property ttl the duration from the time this token is minted until its expiration + * @property timeToLive the duration from the time this token is minted until its expiration */ -@Serializable internal data class AuthExchangeTokenP(val accessToken: String, val ttl: String) +@Serializable +internal data class AuthExchangeTokenP( + val accessToken: String, + @SerialName("timeToLive") val timeToLive: String +) /** * Request header for the `/ExchangeInstallationAuthToken` endpoint. From 1817518ab0d4286e95028126ea946c125c6153a6 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 13 Jan 2023 23:48:00 -0600 Subject: [PATCH 6/6] Fixed typo --- .../kotlin/com/google/firebase/authexchange/network/Routes.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt index c7ce909eec3..d10c9a95bf8 100644 --- a/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt +++ b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt @@ -33,7 +33,7 @@ import kotlinx.serialization.Serializable @Serializable internal data class AuthExchangeTokenP( val accessToken: String, - @SerialName("timeToLive") val timeToLive: String + @SerialName("ttl") val timeToLive: String ) /**