mirror of
https://github.com/YTVanced/VancedMicroG
synced 2024-11-27 21:53:00 +00:00
Update Auth API
This commit is contained in:
parent
a1079e12be
commit
249c935f44
5 changed files with 59 additions and 11 deletions
2
extern/GmsApi
vendored
2
extern/GmsApi
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 5ed675a90b0d9831b06845ba2b95d7de3433acf6
|
||||
Subproject commit a55281ec5d48681e071b85290fc020ea56af482c
|
|
@ -17,8 +17,8 @@
|
|||
<manifest
|
||||
package="com.google.android.gms"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="8115238"
|
||||
android:versionName="8.1.15 (microG v0.01)">
|
||||
android:versionCode="8489238"
|
||||
android:versionName="8.4.89 (microG v0.02)">
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="14"
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.util.Log;
|
|||
|
||||
import com.google.android.gms.R;
|
||||
|
||||
import org.microg.gms.common.Constants;
|
||||
import org.microg.gms.common.PackageUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -120,12 +121,13 @@ public class AuthManager {
|
|||
}
|
||||
|
||||
public String peekAuthToken() {
|
||||
Log.d(TAG, "peekAuthToken: " + buildTokenKey());
|
||||
return getAccountManager().peekAuthToken(getAccount(), buildTokenKey());
|
||||
}
|
||||
|
||||
public String getAuthToken() {
|
||||
if (service.startsWith("weblogin:")) return null;
|
||||
if (getExpiry() != -1 && getExpiry() < System.currentTimeMillis() / 1000L) {
|
||||
if (getExpiry() < System.currentTimeMillis() / 1000L) {
|
||||
Log.d(TAG, "token present, but expired");
|
||||
return null;
|
||||
}
|
||||
|
@ -178,6 +180,11 @@ public class AuthManager {
|
|||
}
|
||||
|
||||
public AuthResponse requestAuth(boolean legacy) throws IOException {
|
||||
if (service.equals(Constants.SCOPE_GET_ACCOUNT_ID)) {
|
||||
AuthResponse response = new AuthResponse();
|
||||
response.accountId = response.auth = getAccountManager().getUserData(getAccount(), "GoogleUserId");
|
||||
return response;
|
||||
}
|
||||
if (isPermitted() || isTrustGooglePermitted(context)) {
|
||||
String token = getAuthToken();
|
||||
if (token != null) {
|
||||
|
|
|
@ -32,10 +32,14 @@ import com.google.android.auth.IAuthManagerService;
|
|||
import com.google.android.gms.R;
|
||||
import com.google.android.gms.auth.AccountChangeEventsRequest;
|
||||
import com.google.android.gms.auth.AccountChangeEventsResponse;
|
||||
import com.google.android.gms.auth.TokenData;
|
||||
import com.google.android.gms.common.api.Scope;
|
||||
|
||||
import org.microg.gms.common.PackageUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.accounts.AccountManager.KEY_ACCOUNT_NAME;
|
||||
import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
|
||||
|
@ -83,16 +87,19 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
|||
scope = scope.replace("https://www.googleapis.com/auth/identity.plus.page.impersonation ", "");
|
||||
|
||||
AuthManager authManager = new AuthManager(context, accountName, packageName, scope);
|
||||
Bundle result = new Bundle();
|
||||
result.putString(KEY_ACCOUNT_NAME, accountName);
|
||||
result.putString(KEY_ACCOUNT_TYPE, authManager.getAccountType());
|
||||
try {
|
||||
AuthResponse res = authManager.requestAuth(false);
|
||||
if (res.auth != null) {
|
||||
Log.d(TAG, "getToken: " + res.auth);
|
||||
Bundle result = new Bundle();
|
||||
Log.d(TAG, "getToken: " + res);
|
||||
result.putString(KEY_AUTHTOKEN, res.auth);
|
||||
Bundle details = new Bundle();
|
||||
details.putParcelable("TokenData", new TokenData(res.auth, res.expiry, scope.startsWith("oauth2:"), getScopes(scope)));
|
||||
result.putBundle("tokenDetails", details);
|
||||
result.putString(KEY_ERROR, "OK");
|
||||
return result;
|
||||
} else {
|
||||
Bundle result = new Bundle();
|
||||
result.putString(KEY_ERROR, "NeedPermission");
|
||||
Intent i = new Intent(context, AskPermissionActivity.class);
|
||||
i.putExtras(extras);
|
||||
|
@ -116,14 +123,22 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
|||
.build());
|
||||
}
|
||||
result.putParcelable(KEY_USER_RECOVERY_INTENT, i);
|
||||
return result;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
Bundle result = new Bundle();
|
||||
result.putString(KEY_ERROR, "NetworkError");
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Scope> getScopes(String scope) {
|
||||
if (!scope.startsWith("oauth2:")) return null;
|
||||
String[] strings = scope.substring(7).split(" ");
|
||||
List<Scope> res = new ArrayList<Scope>();
|
||||
for (String string : strings) {
|
||||
res.add(new Scope(string));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static CharSequence getPackageLabel(String packageName, PackageManager pm) {
|
||||
|
|
|
@ -92,4 +92,30 @@ public class AuthResponse {
|
|||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("AuthResponse{");
|
||||
sb.append("auth='").append(auth).append('\'');
|
||||
if (Sid != null) sb.append(", Sid='").append(Sid).append('\'');
|
||||
if (LSid != null) sb.append(", LSid='").append(LSid).append('\'');
|
||||
if (token != null) sb.append(", token='").append(token).append('\'');
|
||||
if (email != null) sb.append(", email='").append(email).append('\'');
|
||||
if (services != null) sb.append(", services='").append(services).append('\'');
|
||||
if (isGooglePlusUpgrade) sb.append(", isGooglePlusUpgrade=").append(isGooglePlusUpgrade);
|
||||
if (picasaUserName != null) sb.append(", picasaUserName='").append(picasaUserName).append('\'');
|
||||
if (ropText != null) sb.append(", ropText='").append(ropText).append('\'');
|
||||
if (ropRevision != 0) sb.append(", ropRevision=").append(ropRevision);
|
||||
if (firstName != null) sb.append(", firstName='").append(firstName).append('\'');
|
||||
if (lastName != null) sb.append(", lastName='").append(lastName).append('\'');
|
||||
if (issueAdvice != null) sb.append(", issueAdvice='").append(issueAdvice).append('\'');
|
||||
if (accountId != null) sb.append(", accountId='").append(accountId).append('\'');
|
||||
if (expiry != -1) sb.append(", expiry=").append(expiry);
|
||||
if (!storeConsentRemotely) sb.append(", storeConsentRemotely=").append(storeConsentRemotely);
|
||||
if (permission != null) sb.append(", permission='").append(permission).append('\'');
|
||||
if (scopeConsentDetails != null) sb.append(", scopeConsentDetails='").append(scopeConsentDetails).append('\'');
|
||||
if (consentDataBase64 != null) sb.append(", consentDataBase64='").append(consentDataBase64).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue