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

Include app2app device key JWT in the code exchange of reauthentication #175

Merged
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
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