Skip to content

Commit 8ec6d24

Browse files
authored
Auth: Obtain auth again after consent (#3328)
1 parent e6d21be commit 8ec6d24

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

play-services-core/src/main/kotlin/org/microg/gms/auth/signin/AuthSignInActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ class AuthSignInActivity : AppCompatActivity() {
179179
}
180180

181181
private suspend fun signIn(account: Account) {
182-
val (_, googleSignInAccount) = performSignIn(this, config?.packageName!!, config?.options, account, true, idNonce)
182+
val (accessToken, googleSignInAccount) = performSignIn(this, config?.packageName!!, config?.options, account, true, idNonce)
183183
if (googleSignInAccount != null) {
184-
finishResult(CommonStatusCodes.SUCCESS, account = account, googleSignInAccount = googleSignInAccount)
184+
finishResult(CommonStatusCodes.SUCCESS, account = account, googleSignInAccount = googleSignInAccount, accessToken = accessToken)
185185
} else {
186186
finishResult(CommonStatusCodes.INTERNAL_ERROR, "Sign in failed")
187187
}
188188
}
189189

190-
private fun finishResult(statusCode: Int, message: String? = null, account: Account? = null, googleSignInAccount: GoogleSignInAccount? = null) {
190+
private fun finishResult(statusCode: Int, message: String? = null, account: Account? = null, googleSignInAccount: GoogleSignInAccount? = null, accessToken: String? = null) {
191191
val data = Intent()
192192
if (statusCode != CommonStatusCodes.SUCCESS) data.putExtra(AuthConstants.ERROR_CODE, statusCode)
193193
data.putExtra(AuthConstants.GOOGLE_SIGN_IN_STATUS, Status(statusCode, message))
@@ -196,7 +196,7 @@ class AuthSignInActivity : AppCompatActivity() {
196196
if (googleSignInAccount != null) {
197197
val authorizationResult = AuthorizationResult(
198198
googleSignInAccount.serverAuthCode,
199-
googleSignInAccount.idToken,
199+
accessToken,
200200
googleSignInAccount.idToken,
201201
googleSignInAccount.grantedScopes.map { it.scopeUri },
202202
googleSignInAccount,

play-services-core/src/main/kotlin/org/microg/gms/auth/signin/extensions.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ suspend fun checkAccountAuthStatus(context: Context, packageName: String, scopeL
109109

110110
suspend fun performSignIn(context: Context, packageName: String, options: GoogleSignInOptions?, account: Account, permitted: Boolean = false, idNonce: String? = null): Pair<String?, GoogleSignInAccount?> {
111111
val authManager = getOAuthManager(context, packageName, options, account)
112-
val authResponse = withContext(Dispatchers.IO) {
112+
var authResponse = withContext(Dispatchers.IO) {
113113
if (options?.includeUnacceptableScope == true || !permitted) {
114114
authManager.setTokenRequestOptions(consentRequestOptions)
115115
}
@@ -120,9 +120,12 @@ suspend fun performSignIn(context: Context, packageName: String, options: Google
120120
if ("remote_consent" == authResponse.issueAdvice && authResponse.resolutionDataBase64 != null){
121121
consentResult = performConsentView(context, packageName, account, authResponse.resolutionDataBase64)
122122
if (consentResult == null) return Pair(null, null)
123-
} else {
124-
if (authResponse.auth == null) return Pair(null, null)
123+
authResponse = authManager.let {
124+
it.putDynamicFiled(CONSENT_RESULT, consentResult)
125+
withContext(Dispatchers.IO) { it.requestAuth(true) }
126+
}
125127
}
128+
if (authResponse.auth == null) return Pair(null, null)
126129
Log.d(TAG, "id token requested: ${options?.isIdTokenRequested == true}, serverClientId = ${options?.serverClientId}, permitted = ${authManager.isPermitted}")
127130
val idTokenResponse = getIdTokenManager(context, packageName, options, account)?.let {
128131
if (idNonce != null) {

0 commit comments

Comments
 (0)