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

PSG-4820 #80

Merged
merged 5 commits into from
Sep 25, 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
12 changes: 9 additions & 3 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,32 @@ jobs:
sed -i "s/versionCode .*/versionCode $new_version_code/" passage/build.gradle
echo "Updated to patch version $new_version with version code $new_version_code"

- name: Update version in README - major release
- name: Update version in README and PassageClientService - major release
if: ${{ github.event.inputs.release-type == 'major' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-major }}
sed -i "s/implementation 'id\.passage\.android:passage:[0-9]*\.[0-9]*\.[0-9]*'/implementation 'id.passage.android:passage:$new_version'/" README.md
echo "Updated README to version $new_version"
sed -i "s/private const val PACKAGE_VERSION_NUMBER = \"[0-9]*\.[0-9]*\.[0-9]*\"/private const val PACKAGE_VERSION_NUMBER = \"$new_version\"/" passage/src/main/java/id/passage/android/services/PassageClientService.kt
echo "Updated PassageClientService to version $new_version"

- name: Update version in README - minor release
- name: Update version in README and PassageClientService - minor release
if: ${{ github.event.inputs.release-type == 'minor' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-minor }}
sed -i "s/implementation 'id\.passage\.android:passage:[0-9]*\.[0-9]*\.[0-9]*'/implementation 'id.passage.android:passage:$new_version'/" README.md
echo "Updated README to version $new_version"
sed -i "s/private const val PACKAGE_VERSION_NUMBER = \"[0-9]*\.[0-9]*\.[0-9]*\"/private const val PACKAGE_VERSION_NUMBER = \"$new_version\"/" passage/src/main/java/id/passage/android/services/PassageClientService.kt
echo "Updated PassageClientService to version $new_version"

- name: Update version in README - patch release
- name: Update version in README and PassageClientService - patch release
if: ${{ github.event.inputs.release-type == 'patch' }}
run: |
new_version=${{ needs.determine-next-versions.outputs.next-patch }}
sed -i "s/implementation 'id\.passage\.android:passage:[0-9]*\.[0-9]*\.[0-9]*'/implementation 'id.passage.android:passage:$new_version'/" README.md
echo "Updated README to version $new_version"
sed -i "s/private const val PACKAGE_VERSION_NUMBER = \"[0-9]*\.[0-9]*\.[0-9]*\"/private const val PACKAGE_VERSION_NUMBER = \"$new_version\"/" passage/src/main/java/id/passage/android/services/PassageClientService.kt
echo "Updated PassageClientService to version $new_version"

- name: Commit major version change
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal class ChangeContactTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, IntegrationTestConfig.APP_ID_OTP)
passage.overrideBasePath(IntegrationTestConfig.API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal class IntegrationTestConfig {
const val AUTH_TOEKN = BuildConfig.OTP_TEST_USER_AUTH_TOKEN
val CURRENT_USER =
PublicUserInfo(
email = "authentigator+1724103897318@ncor7c1m.mailosaur.net",
email = "authentigator+1727293832645@ncor7c1m.mailosaur.net",
emailVerified = true,
id = "vIfrBSgiQ8Ql6lEdzHyV3biS",
id = "ZN2JTd6NqbTAvN45SbjUzqVn",
phone = "",
phoneVerified = false,
status = UserStatus.active,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal class PassageCurrentUserTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, IntegrationTestConfig.APP_ID_OTP)
passage.overrideBasePath(IntegrationTestConfig.API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.google.common.truth.Truth.assertThat
import id.passage.android.IntegrationTestConfig.Companion.API_BASE_URL
import id.passage.android.IntegrationTestConfig.Companion.APP_ID_OIDC
import id.passage.android.exceptions.HostedAuthorizationError
import junit.framework.TestCase.fail
Expand All @@ -35,7 +34,6 @@ internal class PassageHostedTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, APP_ID_OIDC)
passage.overrideBasePath(API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MailosaurAPIClient
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import id.passage.android.IntegrationTestConfig.Companion.API_BASE_URL
import id.passage.android.IntegrationTestConfig.Companion.APP_ID_MAGIC_LINK
import id.passage.android.IntegrationTestConfig.Companion.DEACTIVATED_USER_EMAIL_MAGIC_LINK
import id.passage.android.IntegrationTestConfig.Companion.EXISTING_USER_EMAIL_MAGIC_LINK
Expand All @@ -31,7 +30,6 @@ internal class PassageMagicLinkTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, APP_ID_MAGIC_LINK)
passage.overrideBasePath(API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MailosaurAPIClient
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import id.passage.android.IntegrationTestConfig.Companion.API_BASE_URL
import id.passage.android.IntegrationTestConfig.Companion.APP_ID_OTP
import id.passage.android.IntegrationTestConfig.Companion.EXISTING_USER_EMAIL_OTP
import id.passage.android.IntegrationTestConfig.Companion.WAIT_TIME_MILLISECONDS
Expand All @@ -29,7 +28,6 @@ internal class PassageOneTimePasscodeTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, APP_ID_OTP)
passage.overrideBasePath(API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ internal class PassageSocialTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, APP_ID_OTP)
passage.overrideBasePath(API_BASE_URL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import MailosaurAPIClient
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import id.passage.android.IntegrationTestConfig.Companion.API_BASE_URL
import id.passage.android.IntegrationTestConfig.Companion.APP_ID_OTP
import id.passage.android.IntegrationTestConfig.Companion.EXISTING_USER_EMAIL_OTP
import id.passage.android.IntegrationTestConfig.Companion.WAIT_TIME_MILLISECONDS
Expand Down Expand Up @@ -35,7 +34,6 @@ internal class TokenStoreTests {
activityRule?.scenario?.onActivity { activity ->
activity?.let {
passage = Passage(it, APP_ID_OTP)
passage.overrideBasePath(API_BASE_URL)
}
}
// Log in user
Expand Down
13 changes: 13 additions & 0 deletions passage/src/androidTest/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<resources>
<string name="app_name">Test App</string>

<!-- Required Passage app settings -->
<string name="passage_auth_origin">try-uat.passage.dev</string>
<string name="clientApiBasePath">https://auth-uat.passage.dev/v1</string>
<string name="asset_statements">
[{
\"include\": \"https://@string/passage_auth_origin/.well-known/assetlinks.json\"
}]
</string>

</resources>
23 changes: 3 additions & 20 deletions passage/src/main/java/id/passage/android/Passage.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package id.passage.android

import PassageClientService
import android.app.Activity
import android.webkit.WebSettings
import id.passage.android.utils.ResourceUtils.Companion.getRequiredResourceFromApp
import okhttp3.OkHttpClient

Expand All @@ -23,7 +23,6 @@ class Passage(
// region CONSTANTS AND SINGLETON VARIABLES
internal companion object {
internal const val TAG = "Passage"
internal var BASE_PATH = "https://auth.passage.id/v1"
internal lateinit var appId: String
internal lateinit var authOrigin: String
}
Expand All @@ -32,19 +31,7 @@ class Passage(

init {
authOrigin = getRequiredResourceFromApp(activity, "passage_auth_origin")
val userAgent = WebSettings.getDefaultUserAgent(activity) ?: "Android"
passageClient =
OkHttpClient
.Builder()
.addNetworkInterceptor { chain ->
chain.proceed(
chain
.request()
.newBuilder()
.header("User-Agent", userAgent)
.build(),
)
}.build()
passageClient = PassageClientService.setup(activity)
Companion.appId = appId
tokenStore = PassageTokenStore(activity)
app = PassageApp(passageClient)
Expand All @@ -53,10 +40,6 @@ class Passage(
hosted = PassageHosted(activity, tokenStore)
social = PassageSocial(passageClient, activity, tokenStore)
magicLink = PassageMagicLink(passageClient, tokenStore)
currentUser = PassageCurrentUser(tokenStore, activity)
}

public fun overrideBasePath(newPath: String) {
BASE_PATH = newPath
currentUser = PassageCurrentUser(tokenStore, activity, passageClient)
}
}
7 changes: 4 additions & 3 deletions passage/src/main/java/id/passage/android/PassageApp.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package id.passage.android

import PassageClientService
import id.passage.android.api.AppsAPI
import id.passage.android.api.UsersAPI
import id.passage.android.exceptions.AppInfoException
Expand All @@ -21,7 +22,7 @@ class PassageApp(
* @throws AppInfoException
*/
suspend fun info(): PassageAppInfo {
val appsAPI = AppsAPI(Passage.BASE_PATH, passageClient)
val appsAPI = AppsAPI(PassageClientService.basePath, passageClient)
return try {
appsAPI.getApp(Passage.appId)
} catch (e: Exception) {
Expand All @@ -39,7 +40,7 @@ class PassageApp(
* @return PublicUserInfo?
*/
suspend fun userExists(identifier: String): PublicUserInfo? {
val usersAPI = UsersAPI()
val usersAPI = UsersAPI(PassageClientService.basePath, passageClient)
return try {
usersAPI.checkUserIdentifier(Passage.appId, identifier).user
} catch (e: Exception) {
Expand All @@ -61,7 +62,7 @@ class PassageApp(
identifier: String,
userMetadata: Any?,
): PublicUserInfo {
val usersAPI = UsersAPI()
val usersAPI = UsersAPI(PassageClientService.basePath, passageClient)
return try {
usersAPI.createUser(Passage.appId, CreateUserParams(identifier, userMetadata)).user ?: throw Exception("User is null")
} catch (e: Exception) {
Expand Down
24 changes: 13 additions & 11 deletions passage/src/main/java/id/passage/android/PassageCurrentUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import id.passage.android.utils.Passkey
import id.passage.android.utils.PasskeyCreationOptions
import id.passage.android.utils.PasskeyUtils
import id.passage.android.utils.SocialConnection
import okhttp3.OkHttpClient

class PassageCurrentUser(
private val tokenStore: PassageTokenStore,
private val activity: Activity,
private val passageClient: OkHttpClient,
) {
/**
* Get Current User
Expand All @@ -38,7 +40,7 @@ class PassageCurrentUser(
* @throws PassageUserException
*/
suspend fun userInfo(): CurrentUserInfo {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
try {
return currentUserAPI.getCurrentuser(Passage.appId).user
} catch (e: Exception) {
Expand All @@ -59,7 +61,7 @@ class PassageCurrentUser(
newEmail: String,
language: String? = null,
): MagicLink {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
val request = UpdateUserEmailRequest(newEmail, language, null, null)
val response =
try {
Expand All @@ -83,7 +85,7 @@ class PassageCurrentUser(
newPhone: String,
language: String? = null,
): MagicLink {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
val request = UpdateUserPhoneRequest(language, null, newPhone, null)
val response =
try {
Expand All @@ -102,7 +104,7 @@ class PassageCurrentUser(
* @throws PassageUserException
*/
suspend fun passkeys(): List<Passkey> {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
return try {
currentUserAPI.getCurrentuserDevices(Passage.appId).devices
} catch (e: Exception) {
Expand All @@ -121,7 +123,7 @@ class PassageCurrentUser(
*/
suspend fun addPasskey(options: PasskeyCreationOptions? = null): Passkey {
try {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
// Get Create Credential challenge from Passage
val authenticatorAttachment =
options?.authenticatorAttachment
Expand Down Expand Up @@ -154,7 +156,7 @@ class PassageCurrentUser(
* @throws PassageUserException
*/
suspend fun deletePasskey(passkeyId: String) {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
try {
currentUserAPI.deleteCurrentuserDevice(Passage.appId, passkeyId)
} catch (e: Exception) {
Expand All @@ -176,7 +178,7 @@ class PassageCurrentUser(
passkeyId: String,
friendlyName: String,
): Passkey {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
val request = UpdateDeviceRequest(friendlyName = friendlyName)
return try {
currentUserAPI.updateCurrentuserDevice(Passage.appId, passkeyId, request).device
Expand All @@ -193,7 +195,7 @@ class PassageCurrentUser(
* @throws PassageUserException If an error occurs during the retrieval process
*/
suspend fun socialConnections(): UserSocialConnections {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath)
try {
return currentUserAPI.getCurrentuserSocialConnections(Passage.appId).socialConnections
} catch (e: Exception) {
Expand All @@ -209,7 +211,7 @@ class PassageCurrentUser(
* @throws PassageUserException If an error occurs during the deletion process
*/
suspend fun deleteSocialConnection(socialConnectionType: SocialConnection) {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
try {
return currentUserAPI.deleteCurrentuserSocialConnection(Passage.appId, socialConnectionType)
} catch (e: Exception) {
Expand All @@ -225,7 +227,7 @@ class PassageCurrentUser(
* @return Metadata? containing the current user's metadata, null if retrieval fails
*/
suspend fun metadata(): Metadata? {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
return try {
currentUserAPI.getCurrentuserMetadata(Passage.appId)
} catch (e: Exception) {
Expand All @@ -242,7 +244,7 @@ class PassageCurrentUser(
* @return CurrentUserInfo? containing the updated user information, null if the update fails
*/
suspend fun updateMetadata(metadata: Metadata): CurrentUserInfo? {
val currentUserAPI = CurrentuserAPI(Passage.BASE_PATH)
val currentUserAPI = CurrentuserAPI(PassageClientService.basePath, passageClient)
val request = UpdateMetadataRequest(userMetadata = metadata.userMetadata)
return try {
currentUserAPI.updateCurrentuserMetadata(Passage.appId, request).user
Expand Down
12 changes: 6 additions & 6 deletions passage/src/main/java/id/passage/android/PassageMagicLink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class PassageMagicLink(
identifier: String,
language: String? = null,
): MagicLink {
val registerAPI = RegisterAPI(Passage.BASE_PATH, passageClient)
val registerAPI = RegisterAPI(PassageClientService.basePath, passageClient)
val request =
RegisterMagicLinkRequest(
identifier = identifier,
language = language
language = language,
)
val magicLink =
try {
Expand All @@ -62,11 +62,11 @@ class PassageMagicLink(
identifier: String,
language: String? = null,
): MagicLink {
val loginAPI = LoginAPI(Passage.BASE_PATH, passageClient)
val loginAPI = LoginAPI(PassageClientService.basePath, passageClient)
val request =
LoginMagicLinkRequest(
identifier = identifier,
language = language
language = language,
)
val response =
try {
Expand All @@ -87,7 +87,7 @@ class PassageMagicLink(
* @throws MagicLinkActivateException
*/
suspend fun activate(magicLink: String): AuthResult {
val magicLinkAPI = MagicLinkAPI(Passage.BASE_PATH, passageClient)
val magicLinkAPI = MagicLinkAPI(PassageClientService.basePath, passageClient)
val request = ActivateMagicLinkRequest(magicLink)
val response =
try {
Expand All @@ -111,7 +111,7 @@ class PassageMagicLink(
* @throws GetMagicLinkStatusException
*/
suspend fun status(id: String): AuthResult {
val magicLinkAPI = MagicLinkAPI(Passage.BASE_PATH, passageClient)
val magicLinkAPI = MagicLinkAPI(PassageClientService.basePath, passageClient)
val request = GetMagicLinkStatusRequest(id)
val response =
try {
Expand Down
Loading
Loading