Skip to content

Commit 18ecb30

Browse files
Add reauthenticateV2
ref DEV-3022
2 parents 90e4369 + ea30ce9 commit 18ecb30

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

sdk/src/main/java/com/oursky/authgear/latte/Latte.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ class Latte(
182182
return Pair(fragment, handle)
183183
}
184184

185+
suspend fun reauthenticateV2(
186+
context: Context,
187+
coroutineScope: CoroutineScope,
188+
options: ReauthenticateV2Options
189+
): Pair<Fragment, LatteHandle<UserInfo>> {
190+
val request = authgear.createReauthenticateRequest(makeAuthgearReauthenticateOptionsV2(context, options))
191+
val fragment = LatteFragment.makeWithPreCreatedWebView(
192+
context = context,
193+
id = makeID(),
194+
url = request.url,
195+
redirectUri = request.redirectUri,
196+
webContentsDebuggingEnabled = webContentsDebuggingEnabled
197+
)
198+
199+
val listenHandle = fragment.listen(authgear.core.application, this)
200+
fragment.waitWebViewToLoad(webViewLoadTimeoutMillis)
201+
202+
val d = coroutineScope.async {
203+
val result = waitForResult(listenHandle)
204+
val userInfo = authgear.finishReauthentication(result.getOrThrow().toString(), request)
205+
userInfo
206+
}
207+
208+
val handle = LatteHandle(fragment.latteID, d)
209+
return Pair(fragment, handle)
210+
}
211+
185212
suspend fun verifyEmail(
186213
context: Context,
187214
coroutineScope: CoroutineScope,
@@ -571,4 +598,22 @@ class Latte(
571598
uiLocales = latteOptions.uiLocales
572599
)
573600
}
601+
602+
private suspend fun makeAuthgearReauthenticateOptionsV2(context: Context, latteOptions: ReauthenticateV2Options): com.oursky.authgear.ReauthenticateOptions {
603+
val reauthXState = HashMap(latteOptions.xState)
604+
reauthXState["user_initiate"] = "reauthv2"
605+
606+
val reauthXSecrets = hashMapOf(
607+
"email" to latteOptions.email,
608+
"phone" to latteOptions.phone
609+
)
610+
611+
val finalXState = makeXStateWithSecrets(reauthXState, reauthXSecrets)
612+
613+
return ReauthenticateOptions(
614+
xState = finalXState.toQueryParameter(),
615+
redirectUri = "latte://complete",
616+
uiLocales = latteOptions.uiLocales
617+
)
618+
}
574619
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.oursky.authgear.latte
2+
3+
data class ReauthenticateV2Options @JvmOverloads constructor(
4+
var email: String,
5+
var phone: String,
6+
var xState: Map<String, String> = mapOf(),
7+
var uiLocales: List<String>? = null
8+
)

0 commit comments

Comments
 (0)