Skip to content
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
5 changes: 5 additions & 0 deletions sdk/src/main/kotlin/com/idme/auth/auth/IDmeAuthManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import com.idme.auth.errors.IDmeAuthError
import java.util.concurrent.ConcurrentHashMap
import java.lang.ref.WeakReference
import kotlinx.coroutines.CompletableDeferred

/**
Expand All @@ -21,6 +22,8 @@ import kotlinx.coroutines.CompletableDeferred
internal object IDmeAuthManager {
private val pending = ConcurrentHashMap<String, CompletableDeferred<String>>()

internal var callingActivity: WeakReference<Activity>? = null

/**
* Launches the authentication flow in a Chrome Custom Tab and suspends
* until the redirect is received.
Expand All @@ -33,6 +36,7 @@ internal object IDmeAuthManager {
suspend fun launchAuth(activity: Activity, authUrl: String, sessionId: String): String {
val deferred = CompletableDeferred<String>()
pending[sessionId] = deferred
callingActivity = WeakReference(activity)

val customTabsIntent = CustomTabsIntent.Builder()
.setShowTitle(true)
Expand All @@ -45,6 +49,7 @@ internal object IDmeAuthManager {
} catch (e: kotlinx.coroutines.CancellationException) {
throw IDmeAuthError.UserCancelled
} finally {
callingActivity = null
pending.remove(sessionId)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.idme.auth.auth

import android.app.Activity
import android.content.Intent
import android.os.Bundle

/**
Expand Down Expand Up @@ -47,6 +48,13 @@ class IDmeRedirectActivity : Activity() {
} else {
IDmeAuthManager.handleCancel()
}
IDmeAuthManager.callingActivity?.get()?.let { activity ->
val intent = Intent(this, activity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
}
startActivity(intent)
}

finish()
}
}
Loading