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

Games: Improve login auth scope logic #2273

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ public Builder requestScopes(@NonNull Scope scope, @NonNull Scope... scopes) {
return this;
}

/**
* Specifies OAuth 2.0 scopes your application requests. See {@link Scopes} for more information.
*
* @param scopes More OAuth 2.0 scopes requested by your app.
*/
@NonNull
public Builder requestScopes(@NonNull List<Scope> scopes) {
this.scopes.addAll(scopes);
return this;
}

mar-v-in marked this conversation as resolved.
Show resolved Hide resolved
/**
* Specifies that offline access is requested. Requesting offline access requires that the server client ID be specified.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package com.google.android.gms.common.api;

parcelable Scope;
3 changes: 3 additions & 0 deletions play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@
android:name="org.microg.gms.auth.signin.AuthSignInActivity"
android:theme="@style/Theme.App.DayNight.Dialog.Alert.NoActionBar"
android:process=":ui"
android:configChanges="keyboardHidden|keyboard|orientation|screenSize"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.auth.GOOGLE_SIGN_IN" />
Expand Down Expand Up @@ -513,6 +514,7 @@
android:name="org.microg.gms.auth.consent.ConsentSignInActivity"
android:process=":ui"
android:exported="false"
android:configChanges="keyboardHidden|keyboard|orientation|screenSize"
android:theme="@style/Theme.AppCompat.DayNight.Dialog"/>

<!-- Games -->
Expand All @@ -522,6 +524,7 @@
android:enabled="true"
android:exported="false"
android:process=":ui"
android:configChanges="keyboardHidden|keyboard|orientation|screenSize"
android:theme="@style/Theme.App.Translucent"/>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AuthSignInServiceImpl(
val account = account ?: options?.account ?: SignInConfigurationService.getDefaultAccount(context, packageName)
if (account != null && options?.isForceCodeForRefreshToken != true && options?.includeUnacceptableScope != true) {
if (getOAuthManager(context, packageName, options, account).isPermitted || AuthPrefs.isTrustGooglePermitted(context)) {
val googleSignInAccount = performSignIn(context, packageName, options, account)
val googleSignInAccount = performSignIn(context, packageName, options, account, true)
if (googleSignInAccount != null) {
sendResult(googleSignInAccount, Status(CommonStatusCodes.SUCCESS))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import androidx.lifecycle.lifecycleScope
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.auth.api.signin.internal.SignInConfiguration
import com.google.android.gms.common.Scopes
import com.google.android.gms.common.api.Scope
import com.google.android.gms.common.api.Status
import org.microg.gms.auth.AuthConstants
import org.microg.gms.auth.signin.AuthSignInActivity
Expand All @@ -31,6 +33,11 @@ class GamesSignInActivity : AppCompatActivity() {
get() = intent?.getParcelableExtra(EXTRA_ACCOUNT)
val popupGravity: Int
get() = intent?.getIntExtra(EXTRA_POPUP_GRAVITY, Gravity.TOP or Gravity.CENTER_HORIZONTAL) ?: (Gravity.TOP or Gravity.CENTER_HORIZONTAL)
val scopes: List<Scope>
get() {
val scopes = intent?.getParcelableArrayExtra(EXTRA_SCOPES)
return scopes?.filterIsInstance<Scope>()?.realScopes ?: arrayListOf(Scope(Scopes.GAMES_LITE))
}

private val Int.px: Int get() = (this * resources.displayMetrics.density).toInt()

Expand All @@ -41,19 +48,22 @@ class GamesSignInActivity : AppCompatActivity() {

window.setGravity(popupGravity)
startActivityForResult(Intent(this, AuthSignInActivity::class.java).apply {
Log.d(TAG, "Sign in for $gamePackageName account:${account?.name} scopes:$scopes")
putExtra("config", SignInConfiguration().apply {
packageName = gamePackageName
val optionsBuilder =
GoogleSignInOptions.Builder().requestScopes(scopes).requestProfile().requestId().requestEmail()
mar-v-in marked this conversation as resolved.
Show resolved Hide resolved
options = account?.name?.takeIf { it != AuthConstants.DEFAULT_ACCOUNT }?.let {
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).setAccountName(it).build()
} ?: GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
optionsBuilder.setAccountName(it).build()
} ?: optionsBuilder.build()
})
Log.d(TAG, "Redirect to GOOGLE_SIGN_IN using $this")
}, REQUEST_CODE_GOOGLE_SIGN_IN)
}

private suspend fun signIn(account: Account) {
Log.d(TAG, "Sign in as $account")
if (performGamesSignIn(this, gamePackageName!!, account, permitted = true)) {
Log.d(TAG, "Sign in as ${account.name}")
if (performGamesSignIn(this, gamePackageName!!, account, permitted = true, scopes = scopes)) {
GamesConfigurationService.setDefaultAccount(this, gamePackageName, account)
}
setResult(RESULT_OK, Intent().apply {
Expand Down