From 2881e920ecc15ff4a51a050abc82157282d77946 Mon Sep 17 00:00:00 2001 From: lalwani Date: Tue, 27 Feb 2024 11:35:25 -0800 Subject: [PATCH 1/8] Added config objects for creating AuthContext --- .../uber/sdk2/auth/api/config/AuthContext.kt | 31 +++++++++++++++++ .../sdk2/auth/api/config/AuthDestination.kt | 33 +++++++++++++++++++ .../uber/sdk2/auth/api/config/AuthResponse.kt | 25 ++++++++++++++ .../com/uber/sdk2/auth/api/config/AuthType.kt | 22 +++++++++++++ .../com/uber/sdk2/auth/api/config/CrossApp.kt | 24 ++++++++++++++ .../uber/sdk2/auth/api/config/PrefillInfo.kt | 23 +++++++++++++ 6 files changed, 158 insertions(+) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt new file mode 100644 index 00000000..3035e2bf --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt @@ -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.config + +/** + * 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, +) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt new file mode 100644 index 00000000..085280b6 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt @@ -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.config + +/** 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. + */ + 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) : AuthDestination() +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt new file mode 100644 index 00000000..944161fe --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt @@ -0,0 +1,25 @@ +/* + * 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.config + +import com.uber.sdk2.auth.api.exception.AuthException +import com.uber.sdk2.auth.api.service.AccessToken + +data class AuthResponse( + val authCode: String, + val accessToken: AccessToken, + val authException: AuthException, +) {} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt new file mode 100644 index 00000000..87c13e76 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt @@ -0,0 +1,22 @@ +/* + * 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.config + +sealed class AuthType { + object AuthCode : AuthType() + + object PKCE : AuthType() +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt new file mode 100644 index 00000000..21b81870 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt @@ -0,0 +1,24 @@ +/* + * 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.config + +sealed class CrossApp { + object Eats : CrossApp() + + object Rider : CrossApp() + + object Driver : CrossApp() +} diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt new file mode 100644 index 00000000..22b094b8 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt @@ -0,0 +1,23 @@ +/* + * 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.config + +data class PrefillInfo( + val email: String, + val firstName: String, + val lastName: String, + val mobile: String, +) From 9b13613fc5132f605e44002817dc5b9395aa9983 Mon Sep 17 00:00:00 2001 From: lalwani Date: Tue, 27 Feb 2024 15:52:42 -0800 Subject: [PATCH 2/8] renamed mobile field to phoneNumber --- .../main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt index 22b094b8..fd5b06a4 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt @@ -19,5 +19,5 @@ data class PrefillInfo( val email: String, val firstName: String, val lastName: String, - val mobile: String, + val phoneNumber: String, ) From 374d2bbec5ce98c379f527d49e65a25601589c2c Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 28 Feb 2024 09:54:47 -0800 Subject: [PATCH 3/8] added AuthException class. also added kdocs --- .../uber/sdk2/auth/api/config/AuthContext.kt | 4 +-- .../uber/sdk2/auth/api/config/AuthResponse.kt | 7 +++++ .../com/uber/sdk2/auth/api/config/AuthType.kt | 7 +++++ .../com/uber/sdk2/auth/api/config/CrossApp.kt | 4 +++ .../uber/sdk2/auth/api/config/PrefillInfo.kt | 8 ++++++ .../sdk2/auth/api/exception/AuthException.kt | 28 +++++++++++++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt index 3035e2bf..07588b52 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt @@ -26,6 +26,6 @@ package com.uber.sdk2.auth.api.config data class AuthContext( val authDestination: AuthDestination, val authType: AuthType, - val prefillInfo: PrefillInfo, - val scopes: String, + val prefillInfo: PrefillInfo?, + val scopes: String?, ) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt index 944161fe..e04664c6 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt @@ -18,6 +18,13 @@ package com.uber.sdk2.auth.api.config import com.uber.sdk2.auth.api.exception.AuthException import com.uber.sdk2.auth.api.service.AccessToken +/** + * Represents the response from the authentication request. + * + * @param authCode The authorization code to be used for the token exchange. + * @param accessToken The access token to be used for the API requests. + * @param authException The exception that occurred during the authentication request. + */ data class AuthResponse( val authCode: String, val accessToken: AccessToken, diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt index 87c13e76..1a2adbf9 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt @@ -15,8 +15,15 @@ */ package com.uber.sdk2.auth.api.config +/** + * Represents the type of authentication to perform. + * + * @see AuthContext + */ sealed class AuthType { + /** The authorization code flow. */ object AuthCode : AuthType() + /** The proof key for code exchange (PKCE) flow. This is the recommended flow for mobile apps. */ object PKCE : AuthType() } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt index 21b81870..aa218754 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt @@ -15,10 +15,14 @@ */ package com.uber.sdk2.auth.api.config +/** Provides different apps that could be used for authentication using SSO flow. */ sealed class CrossApp { + /** The Eats app. */ object Eats : CrossApp() + /** The Rider app. */ object Rider : CrossApp() + /** The Driver app. */ object Driver : CrossApp() } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt index fd5b06a4..efdcaf30 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt @@ -15,6 +15,14 @@ */ package com.uber.sdk2.auth.api.config +/** + * 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, diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt new file mode 100644 index 00000000..8c144c88 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt @@ -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) : Throwable(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) +} From 6c029ace19b23a96579c9bbc8974b4eb9f5dc11b Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 28 Feb 2024 10:11:31 -0800 Subject: [PATCH 4/8] added response data classes --- .../api/{config => request}/AuthContext.kt | 2 +- .../{config => request}/AuthDestination.kt | 2 +- .../auth/api/{config => request}/AuthType.kt | 2 +- .../auth/api/{config => request}/CrossApp.kt | 2 +- .../api/{config => request}/PrefillInfo.kt | 2 +- .../sdk2/auth/api/response/AccessToken.kt | 18 +++++++++++++++++ .../api/{config => response}/AuthResponse.kt | 3 +-- .../uber/sdk2/auth/api/response/OAuthToken.kt | 20 +++++++++++++++++++ 8 files changed, 44 insertions(+), 7 deletions(-) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => request}/AuthContext.kt (96%) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => request}/AuthDestination.kt (96%) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => request}/AuthType.kt (95%) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => request}/CrossApp.kt (95%) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => request}/PrefillInfo.kt (96%) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/{config => response}/AuthResponse.kt (92%) create mode 100644 authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthContext.kt similarity index 96% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthContext.kt index 07588b52..f4c34ffb 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthContext.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthContext.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.request /** * Represents the context of the authentication request needed for Uber to authenticate the user. diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt similarity index 96% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt index 085280b6..6cd39555 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthDestination.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.request /** Represents the destination app to authenticate the user. */ sealed class AuthDestination { diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt similarity index 95% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt index 1a2adbf9..0a9afc49 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthType.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.request /** * Represents the type of authentication to perform. diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt similarity index 95% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt index aa218754..bc021f65 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/CrossApp.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.request /** Provides different apps that could be used for authentication using SSO flow. */ sealed class CrossApp { diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/PrefillInfo.kt similarity index 96% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/PrefillInfo.kt index efdcaf30..98c21160 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/PrefillInfo.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/PrefillInfo.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.request /** * Provides a way to prefill the user's information in the authentication flow. diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt new file mode 100644 index 00000000..b87b8a1c --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt @@ -0,0 +1,18 @@ +/* + * 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 + +data class AccessToken(val token: String, val scope: String, val expiresIn: Long) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt similarity index 92% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt index e04664c6..1198fed3 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/config/AuthResponse.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.uber.sdk2.auth.api.config +package com.uber.sdk2.auth.api.response import com.uber.sdk2.auth.api.exception.AuthException -import com.uber.sdk2.auth.api.service.AccessToken /** * Represents the response from the authentication request. diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt new file mode 100644 index 00000000..405229d4 --- /dev/null +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt @@ -0,0 +1,20 @@ +/* + * 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.response.AccessToken + +data class OAuthToken(val accessToken: AccessToken, val refreshToken: String) From 81718f949b725482a3e1251eededbed4f75acddc Mon Sep 17 00:00:00 2001 From: lalwani Date: Wed, 28 Feb 2024 10:19:30 -0800 Subject: [PATCH 5/8] fixed formatting errors --- .../main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt | 1 + .../kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt | 2 +- .../main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt index b87b8a1c..ff71eebb 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AccessToken.kt @@ -15,4 +15,5 @@ */ 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) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt index 1198fed3..937f4540 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt @@ -28,4 +28,4 @@ data class AuthResponse( val authCode: String, val accessToken: AccessToken, val authException: AuthException, -) {} +) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt index 405229d4..b97f915d 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/OAuthToken.kt @@ -15,6 +15,5 @@ */ package com.uber.sdk2.auth.api.response -import com.uber.sdk2.auth.api.response.AccessToken - +/** Holds the OAuth token that is returned after a successful authentication request. */ data class OAuthToken(val accessToken: AccessToken, val refreshToken: String) From 48df4d6dbcedc11c9f97b2564d0a30ebc22ac4c8 Mon Sep 17 00:00:00 2001 From: lalwani Date: Fri, 1 Mar 2024 12:12:39 -0800 Subject: [PATCH 6/8] addressed comments --- .../sdk2/auth/api/exception/AuthException.kt | 2 +- .../sdk2/auth/api/request/AuthDestination.kt | 2 +- .../uber/sdk2/auth/api/request/AuthType.kt | 4 ++-- .../uber/sdk2/auth/api/request/CrossApp.kt | 6 +++--- .../{AuthResponse.kt => AuthResult.kt} | 20 ++++++++++--------- 5 files changed, 18 insertions(+), 16 deletions(-) rename authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/{AuthResponse.kt => AuthResult.kt} (68%) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt index 8c144c88..98c5df54 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/exception/AuthException.kt @@ -16,7 +16,7 @@ package com.uber.sdk2.auth.api.exception /** Represents the exception that occurred during the authentication request. */ -sealed class AuthException(override val message: String) : Throwable(message) { +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) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt index 6cd39555..2df5a2d9 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthDestination.kt @@ -21,7 +21,7 @@ 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. */ - object InApp : AuthDestination() + data object InApp : AuthDestination() /** * Authenticating via one of the family of Uber apps using the Single Sign-On (SSO) flow in the diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt index 0a9afc49..93fbaf04 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/AuthType.kt @@ -22,8 +22,8 @@ package com.uber.sdk2.auth.api.request */ sealed class AuthType { /** The authorization code flow. */ - object AuthCode : AuthType() + data object AuthCode : AuthType() /** The proof key for code exchange (PKCE) flow. This is the recommended flow for mobile apps. */ - object PKCE : AuthType() + data object PKCE : AuthType() } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt index bc021f65..f26ac193 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/request/CrossApp.kt @@ -18,11 +18,11 @@ 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. */ - object Eats : CrossApp() + data object Eats : CrossApp() /** The Rider app. */ - object Rider : CrossApp() + data object Rider : CrossApp() /** The Driver app. */ - object Driver : CrossApp() + data object Driver : CrossApp() } diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt similarity index 68% rename from authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt rename to authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt index 937f4540..6b0cdaf8 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResponse.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt @@ -19,13 +19,15 @@ import com.uber.sdk2.auth.api.exception.AuthException /** * Represents the response from the authentication request. - * - * @param authCode The authorization code to be used for the token exchange. - * @param accessToken The access token to be used for the API requests. - * @param authException The exception that occurred during the authentication request. */ -data class AuthResponse( - val authCode: String, - val accessToken: AccessToken, - val authException: AuthException, -) +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() +} \ No newline at end of file From 2c9de432738bc80afce19d69cbfb8b4368e2409b Mon Sep 17 00:00:00 2001 From: lalwani Date: Sat, 2 Mar 2024 08:00:05 -0800 Subject: [PATCH 7/8] updated kotlin version to 1.9 --- authentication/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authentication/build.gradle.kts b/authentication/build.gradle.kts index cf73c5d8..709f3454 100644 --- a/authentication/build.gradle.kts +++ b/authentication/build.gradle.kts @@ -42,8 +42,8 @@ plugins { tasks.withType().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)) } } From a1a84fabb46f0d88b7626cb09d43cf4ed2cef6d0 Mon Sep 17 00:00:00 2001 From: lalwani Date: Sat, 2 Mar 2024 08:08:01 -0800 Subject: [PATCH 8/8] applied formatting --- .../com/uber/sdk2/auth/api/response/AuthResult.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt index 6b0cdaf8..03d28e1f 100644 --- a/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt +++ b/authentication/src/main/kotlin/com/uber/sdk2/auth/api/response/AuthResult.kt @@ -17,17 +17,11 @@ package com.uber.sdk2.auth.api.response import com.uber.sdk2.auth.api.exception.AuthException -/** - * Represents the response from the authentication request. - */ +/** Represents the response from the authentication request. */ sealed class AuthResult { - /** - * Represents the success response from the authentication request. - */ + /** 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. - */ + /** Represents the error response from the authentication request. */ data class Error(val authException: AuthException) : AuthResult() -} \ No newline at end of file +}