add login with discord
This commit is contained in:
parent
658bcfde60
commit
f64790f41d
File diff suppressed because one or more lines are too long
@ -192,6 +192,21 @@
|
|||||||
android:scheme="cebg"
|
android:scheme="cebg"
|
||||||
android:path="/apple_login_result" />
|
android:path="/apple_login_result" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".discord.DiscordLoginCbActivity"
|
||||||
|
tools:node="replace"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:scheme="cebgdiscordcb"
|
||||||
|
android:path="/discord_login_result" />
|
||||||
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.facebook.FacebookActivity"
|
android:name="com.facebook.FacebookActivity"
|
||||||
|
@ -11,4 +11,9 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String FUNID_PREFIX = "webpage_";
|
public static final String FUNID_PREFIX = "webpage_";
|
||||||
|
|
||||||
|
public static final String DISCORD_CLIENT_ID = "1199290913155981345";
|
||||||
|
// public static final String DISCORD_REDIRECT_URI= "https://oauth-svr.cebggame.com/test/discord/oauth_redirect";
|
||||||
|
public static final String DISCORD_REDIRECT_URI= "https://wallet.cebggame.com/discord/oauth_redirect";
|
||||||
|
public static final String DISCORD_SCOPE = "email identify";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package com.cege.games.release;
|
|||||||
|
|
||||||
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
import static androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
||||||
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL;
|
||||||
|
import static com.cege.games.release.Constants.DISCORD_CLIENT_ID;
|
||||||
|
import static com.cege.games.release.Constants.DISCORD_REDIRECT_URI;
|
||||||
|
import static com.cege.games.release.Constants.DISCORD_SCOPE;
|
||||||
import static org.cocos2dx.lib.Cocos2dxHelper.getActivity;
|
import static org.cocos2dx.lib.Cocos2dxHelper.getActivity;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -56,6 +59,10 @@ import com.jc.jcfw.util.JsonUtils;
|
|||||||
import com.unity3d.player.UnityPlayerActivity;
|
import com.unity3d.player.UnityPlayerActivity;
|
||||||
|
|
||||||
import net.openid.appauth.AuthState;
|
import net.openid.appauth.AuthState;
|
||||||
|
import net.openid.appauth.AuthorizationRequest;
|
||||||
|
import net.openid.appauth.AuthorizationService;
|
||||||
|
import net.openid.appauth.AuthorizationServiceConfiguration;
|
||||||
|
import net.openid.appauth.ResponseTypeValues;
|
||||||
|
|
||||||
import org.cocos2dx.lib.Cocos2dxHelper;
|
import org.cocos2dx.lib.Cocos2dxHelper;
|
||||||
import org.cocos2dx.lib.CocosJSHelper;
|
import org.cocos2dx.lib.CocosJSHelper;
|
||||||
@ -83,6 +90,8 @@ public class MainActivity extends UnityPlayerActivity
|
|||||||
// code for request drive to download
|
// code for request drive to download
|
||||||
private static final int RC_REQUEST_DRIVE_TO_READ = 0X052;
|
private static final int RC_REQUEST_DRIVE_TO_READ = 0X052;
|
||||||
|
|
||||||
|
private static final int RC_DISCORD_LOGIN = 0X053;
|
||||||
|
|
||||||
|
|
||||||
public static final int FILE_SELECTOR_CODE = 0X014;
|
public static final int FILE_SELECTOR_CODE = 0X014;
|
||||||
private String title;
|
private String title;
|
||||||
@ -378,6 +387,28 @@ public class MainActivity extends UnityPlayerActivity
|
|||||||
this.mFunID = funId;
|
this.mFunID = funId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void signWithDiscord(String funId) {
|
||||||
|
AuthorizationServiceConfiguration config = new AuthorizationServiceConfiguration(
|
||||||
|
Uri.parse("https://discord.com/api/oauth2/authorize"),
|
||||||
|
Uri.parse("")
|
||||||
|
);
|
||||||
|
AuthorizationRequest.Builder authRequestBuilder = new AuthorizationRequest.Builder(
|
||||||
|
config,
|
||||||
|
DISCORD_CLIENT_ID,
|
||||||
|
ResponseTypeValues.CODE,
|
||||||
|
Uri.parse(DISCORD_REDIRECT_URI)
|
||||||
|
);
|
||||||
|
String[] scopes = DISCORD_SCOPE.split(" +");
|
||||||
|
AuthorizationRequest authRequest = authRequestBuilder
|
||||||
|
.setScopes(scopes)
|
||||||
|
.setCodeVerifier(null, null, null)
|
||||||
|
.setState(funId)
|
||||||
|
.build();
|
||||||
|
AuthorizationService service = new AuthorizationService(this);
|
||||||
|
Intent authIntent = service.getAuthorizationRequestIntent(authRequest);
|
||||||
|
startActivityForResult(authIntent, RC_DISCORD_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
public void logEvent(String content) {
|
public void logEvent(String content) {
|
||||||
try {
|
try {
|
||||||
Bundle bundle = JsonUtils.convertJsonToBundle(content);
|
Bundle bundle = JsonUtils.convertJsonToBundle(content);
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
package com.cege.games.release.discord;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.cege.games.release.MainActivity;
|
||||||
|
import com.jc.jcfw.JcSDK;
|
||||||
|
|
||||||
|
public class DiscordLoginCbActivity extends Activity{
|
||||||
|
private static final String TAG = DiscordLoginCbActivity.class.getSimpleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Log.d(TAG, "receive discord login callback");
|
||||||
|
Intent intent = getIntent();
|
||||||
|
|
||||||
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
|
Uri uri = intent.getData();
|
||||||
|
String error = uri.getQueryParameter("error");
|
||||||
|
String state = uri.getQueryParameter("state");
|
||||||
|
if (null != error && !error.isEmpty()) {
|
||||||
|
JcSDK.nativeCb(state, error, null);
|
||||||
|
} else {
|
||||||
|
String token = uri.getQueryParameter("token");
|
||||||
|
JcSDK.nativeCb(state, null, token);
|
||||||
|
}
|
||||||
|
Intent intentMain = new Intent(this, MainActivity.class);
|
||||||
|
startActivity(intentMain);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -132,6 +132,10 @@ public class JcSDK {
|
|||||||
MainActivity.app.signWithApple(funid);
|
MainActivity.app.signWithApple(funid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void signWithDiscord(String funid) {
|
||||||
|
MainActivity.app.signWithDiscord(funid);
|
||||||
|
}
|
||||||
|
|
||||||
public static void signOutGoogle(String funid) {
|
public static void signOutGoogle(String funid) {
|
||||||
MainActivity.app.signOutGoogle(funid);
|
MainActivity.app.signOutGoogle(funid);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user