change oauth login, add parse fragment
This commit is contained in:
parent
640311163a
commit
04a804cf79
File diff suppressed because one or more lines are too long
@ -181,9 +181,7 @@
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data
|
||||
android:scheme="cfoauthcb"
|
||||
android:path="/login_result" />
|
||||
<data android:scheme="cfoauthcb" android:path="/login_result" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
|
@ -126,11 +126,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
CocosJSHelper.initJSEnv(getApplicationContext());
|
||||
|
||||
// begin of google sign
|
||||
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.requestScopes(new Scope(Scopes.EMAIL))
|
||||
.requestIdToken(getString(R.string.default_web_client_id1))
|
||||
.build();
|
||||
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
|
||||
// mGoogleSignInClient = initGsiClient();
|
||||
// end of google sign
|
||||
|
||||
// begin of google oauth sign
|
||||
@ -241,6 +237,14 @@ public class MainActivity extends UnityPlayerActivity
|
||||
|
||||
}
|
||||
|
||||
private GoogleSignInClient initGsiClient() {
|
||||
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||
.requestScopes(new Scope(Scopes.EMAIL))
|
||||
.requestIdToken(getString(R.string.default_web_client_id1))
|
||||
.build();
|
||||
return GoogleSignIn.getClient(this, gso);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
@ -252,6 +256,9 @@ public class MainActivity extends UnityPlayerActivity
|
||||
public void signWithGoogle(String funId) {
|
||||
this.mFunID = funId;
|
||||
if (isGooglePlayServicesAvailable()) {
|
||||
if (mGoogleSignInClient == null) {
|
||||
mGoogleSignInClient = initGsiClient();
|
||||
}
|
||||
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
|
||||
if (account != null) {
|
||||
Log.w(TAG, "already login: " + account.getIdToken());
|
||||
@ -289,8 +296,7 @@ public class MainActivity extends UnityPlayerActivity
|
||||
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
|
||||
try {
|
||||
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
|
||||
Log.w(TAG, "signIn success: ");
|
||||
Log.w(TAG, "gsa idToken: " + account.getIdToken());
|
||||
Log.w(TAG, "gso signIn success: " + account.getIdToken());
|
||||
JcSDK.nativeCb(this.mFunID, null, account.getIdToken());
|
||||
// Signed in successfully, show authenticated UI.
|
||||
} catch (ApiException e) {
|
||||
|
@ -28,6 +28,20 @@ public class OAuthLoginCbActivity extends Activity {
|
||||
JcSDK.nativeCb(state, error, null);
|
||||
} else {
|
||||
String token = uri.getQueryParameter("token");
|
||||
// if token is null, get token and state from uri fragment
|
||||
if (null == token || "undefined".equals(token) || token.isEmpty()){
|
||||
String fragment = uri.getFragment();
|
||||
String[] vals = fragment.split("&");
|
||||
for (String val : vals) {
|
||||
if (val.startsWith("token=")) {
|
||||
token = val.substring(6);
|
||||
} else if (val.startsWith("id_token=")) {
|
||||
token = val.substring(9);
|
||||
} else if (val.startsWith("state=")) {
|
||||
state = val.substring(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
JcSDK.nativeCb(state, null, token);
|
||||
}
|
||||
Intent intentMain = new Intent(this, MainActivity.class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user