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

Created request and response objects for sdk 2.x #222

Merged
merged 8 commits into from
Mar 2, 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
4 changes: 2 additions & 2 deletions authentication/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ plugins {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
// Lint forces its embedded kotlin version, so we need to match it.
apiVersion.set(KotlinVersion.KOTLIN_1_7)
languageVersion.set(KotlinVersion.KOTLIN_1_7)
apiVersion.set(KotlinVersion.KOTLIN_1_9)
languageVersion.set(KotlinVersion.KOTLIN_1_9)
jvmTarget.set(libs.versions.jvmTarget.map(JvmTarget::fromTarget))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.exception

/** Represents the exception that occurred during the authentication request. */
sealed class AuthException(override val message: String) : RuntimeException(message) {
/** Represents the exception that occurred due to server error. */
data class ServerError(override val message: String) : AuthException(message)

/** Represents the exception that occurred due to client error. */
data class ClientError(override val message: String) : AuthException(message)

/** Represents the exception that occurred due to network error. */
data class NetworkError(override val message: String) : AuthException(message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.request

/**
* Represents the context of the authentication request needed for Uber to authenticate the user.
*
* @param authDestination The destination app to authenticate the user.
* @param authType The type of authentication to perform.
* @param prefillInfo The prefill information to be used for the authentication.
* @param scopes The scopes to request for the authentication.
*/
data class AuthContext(
val authDestination: AuthDestination,
val authType: AuthType,
val prefillInfo: PrefillInfo?,
val scopes: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.request

/** Represents the destination app to authenticate the user. */
sealed class AuthDestination {
/**
* Authenticating within the same app by using a system webview, a.k.a Custom Tabs. If custom tabs
* are unavailable the authentication flow will be launched in the system browser app.
*/
data object InApp : AuthDestination()

/**
* Authenticating via one of the family of Uber apps using the Single Sign-On (SSO) flow in the
* order of priority mentioned.
*
* @param appPriority The order of the apps to use for the SSO flow.
*/
data class CrossAppSso(val appPriority: List<CrossApp>) : AuthDestination()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.request

/**
* Represents the type of authentication to perform.
*
* @see AuthContext
*/
sealed class AuthType {
/** The authorization code flow. */
data object AuthCode : AuthType()

/** The proof key for code exchange (PKCE) flow. This is the recommended flow for mobile apps. */
data object PKCE : AuthType()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.request

/** Provides different apps that could be used for authentication using SSO flow. */
sealed class CrossApp {
/** The Eats app. */
data object Eats : CrossApp()

/** The Rider app. */
data object Rider : CrossApp()

/** The Driver app. */
data object Driver : CrossApp()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.request

/**
* Provides a way to prefill the user's information in the authentication flow.
*
* @param email The email to prefill.
* @param firstName The first name to prefill.
* @param lastName The last name to prefill.
* @param phoneNumber The phone number to prefill.
*/
data class PrefillInfo(
val email: String,
val firstName: String,
val lastName: String,
val phoneNumber: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.response

/** Holds the access token that is returned after a successful authentication request. */
data class AccessToken(val token: String, val scope: String, val expiresIn: Long)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.response

import com.uber.sdk2.auth.api.exception.AuthException

/** Represents the response from the authentication request. */
sealed class AuthResult {
/** Represents the success response from the authentication request. */
data class Success(val authCode: String, val accessToken: AccessToken) : AuthResult()

/** Represents the error response from the authentication request. */
data class Error(val authException: AuthException) : AuthResult()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2024. Uber Technologies
*
* 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
*
* https://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.
*/
package com.uber.sdk2.auth.api.response

/** Holds the OAuth token that is returned after a successful authentication request. */
data class OAuthToken(val accessToken: AccessToken, val refreshToken: String)
Loading