Skip to content

Commit

Permalink
Include app2app device key JWT in the code exchange of reauthentication
Browse files Browse the repository at this point in the history
  • Loading branch information
tung2744 authored Jan 9, 2024
2 parents ec8f663 + deaa823 commit c555fe7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdk/src/main/java/com/oursky/authgear/AuthgearCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ internal class AuthgearCore(
return userInfo
}

private fun finishReauthentication(deepLink: String): UserInfo {
fun finishReauthentication(deepLink: String, verifier: Verifier? = null): UserInfo {
val uri = Uri.parse(deepLink)
val redirectUri = "${uri.scheme}://${uri.authority}${uri.path}"
val state = uri.getQueryParameter("state")
Expand All @@ -820,15 +820,20 @@ internal class AuthgearCore(
state = state,
errorURI = errorURI
)
val codeVerifier = storage.getOidcCodeVerifier(name)
val codeVerifier = verifier?.verifier ?: storage.getOidcCodeVerifier(name)
var app2appJwt: String? = null
if (app2AppOptions.isEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
app2appJwt = app2app.generateApp2AppJWT(forceNewKey = false)
}
val tokenResponse = oauthRepo.oidcTokenRequest(
OidcTokenRequest(
grantType = GrantType.AUTHORIZATION_CODE,
clientId = clientId,
xDeviceInfo = getDeviceInfo(this.application).toBase64URLEncodedString(),
code = code,
redirectUri = redirectUri,
codeVerifier = codeVerifier ?: ""
codeVerifier = codeVerifier ?: "",
xApp2AppDeviceKeyJwt = app2appJwt
)
)
val userInfo = oauthRepo.oidcUserInfoRequest(tokenResponse.accessToken!!)
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/main/java/com/oursky/authgear/KotlinExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ suspend fun Authgear.finishAuthentication(
}
}

/**
* @see [Authgear.finishReauthentication].
*/
@ExperimentalAuthgearApi
suspend fun Authgear.finishReauthentication(
finishUri: String,
request: AuthenticationRequest
): UserInfo {
return withContext(Dispatchers.IO) {
core.finishReauthentication(finishUri, request.verifier)
}
}

/**
* @see [Authgear.authenticateAnonymously]
*/
Expand Down

0 comments on commit c555fe7

Please sign in to comment.