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..2057b3fa683 --- /dev/null +++ b/firebase-authexchange/firebase-authexchange.gradle.kts @@ -0,0 +1,49 @@ +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 { + implementation(project(":firebase-common")) + implementation(project(":firebase-common:ktx")) + implementation(project(":firebase-components")) + implementation(project(":firebase-authexchange-interop")) + + implementation(libs.androidx.annotation) + implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1") + implementation(libs.kotlin.stdlib) + + + testImplementation(libs.androidx.test.core) + testImplementation(libs.truth) + testImplementation(libs.junit) + testImplementation(libs.robolectric) +} 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..d10c9a95bf8 --- /dev/null +++ b/firebase-authexchange/src/main/kotlin/com/google/firebase/authexchange/network/Routes.kt @@ -0,0 +1,105 @@ +package com.google.firebase.authexchange.network + +import kotlinx.serialization.SerialName +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. + * + * @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 timeToLive the duration from the time this token is minted until its expiration + */ +@Serializable +internal data class AuthExchangeTokenP( + val accessToken: String, + @SerialName("ttl") val timeToLive: String +) + +/** + * Request header for the `/ExchangeInstallationAuthToken` 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 ExchangeInstallationAuthTokenRequestP( + 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 ExchangeInstallationAuthTokenRequestP + * + * @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