Beispiel #1
0
        private void LoginWithCredentialInfo(Dictionary <string, object> credentialInfo, int handle)
        {
            if (false == CanLogin(handle))
            {
                return;
            }

            if (null == credentialInfo ||
                false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.PROVIDER_NAME) ||
                (false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.ACCESS_TOKEN) && false == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.AUTHORIZATION_CODE)))
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_INVALID_IDP_INFO, Domain));
                GamebaseCallbackHandler.UnregisterCallback(handle);
                return;
            }

            var providerName = (string)credentialInfo[GamebaseAuthProviderCredential.PROVIDER_NAME];
            var accessToken  = string.Empty;
            var authCode     = string.Empty;

            if (true == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.ACCESS_TOKEN))
            {
                accessToken = (string)credentialInfo[GamebaseAuthProviderCredential.ACCESS_TOKEN];
            }

            if (true == credentialInfo.ContainsKey(GamebaseAuthProviderCredential.AUTHORIZATION_CODE))
            {
                authCode = (string)credentialInfo[GamebaseAuthProviderCredential.AUTHORIZATION_CODE];
            }

            var requestVO = AuthMessage.GetIDPLoginMessage(providerName, accessToken, authCode);

            RequestGamebaseLogin(requestVO, handle);
        }
Beispiel #2
0
        private void LoginWithProviderName(string providerName, int handle)
        {
            if (false == AuthAdapterManager.Instance.IsSupportedIDP(providerName))
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);
                GamebaseErrorNotifier.FireNotSupportedAPI(
                    this,
                    callback,
                    string.Format("Login({0})", providerName));
                GamebaseCallbackHandler.UnregisterCallback(handle);
                return;
            }

            if (false == CanLogin(handle))
            {
                return;
            }

            if (GamebaseAuthProvider.GUEST == providerName)
            {
                var requestVO = AuthMessage.GetIDPLoginMessage(providerName);
                RequestGamebaseLogin(requestVO, handle);

                return;
            }

            bool hasAdapter = AuthAdapterManager.Instance.CreateIDPAdapter(providerName);

            if (false == hasAdapter)
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, message: GamebaseStrings.AUTH_ADAPTER_NOT_FOUND_NEED_SETUP));
                GamebaseCallbackHandler.UnregisterCallback(handle);
            }

            AuthAdapterManager.Instance.IDPLogin((adapterError) =>
            {
                if (Gamebase.IsSuccess(adapterError))
                {
                    var IDPAccessToken = AuthAdapterManager.Instance.GetIDPData <string>(providerName, AuthAdapterManager.MethodName.GET_IDP_ACCESS_TOKEN);
                    var requestVO      = AuthMessage.GetIDPLoginMessage(providerName, IDPAccessToken);
                    RequestGamebaseLogin(requestVO, handle);

                    return;
                }

                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);
                if (null == callback)
                {
                    return;
                }

                GamebaseCallbackHandler.UnregisterCallback(handle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, Domain, error: adapterError));
                AuthAdapterManager.Instance.IDPLogout(providerName);
            });
        }
Beispiel #3
0
        private void LoginWithProviderName(string providerName, int handle)
        {
            if (GamebaseUnitySDK.UseWebViewLogin == false)
            {
                base.Login(providerName, handle);
                return;
            }

            if (IsSupportedIDPByWebview(providerName) == false)
            {
                base.Login(providerName, handle);
                return;
            }

            if (CanLogin(handle) == false)
            {
                return;
            }

            if (providerName.Equals(GamebaseAuthProvider.GUEST, StringComparison.Ordinal) == true)
            {
                var requestVO = AuthMessage.GetIDPLoginMessage(providerName);
                RequestGamebaseLogin(requestVO, handle);
                return;
            }

            bool hasAdapter = WebviewAdapterManager.Instance.CreateWebviewAdapter("standalonewebviewadapter");

            if (hasAdapter == false)
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);
                GamebaseCallbackHandler.UnregisterCallback(handle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, message: GamebaseStrings.WEBVIEW_ADAPTER_NOT_FOUND));
                return;
            }

            isAuthenticationAlreadyProgress = true;

            GetAccessToken(providerName, (requestVO) =>
            {
                if (requestVO == null)
                {
                    isAuthenticationAlreadyProgress = false;
                    LoginFailedCallback(handle);
                    return;
                }

                RequestGamebaseLogin(requestVO, handle);
            });
        }
Beispiel #4
0
        private void GetAccessToken(string providerName, System.Action <WebSocketRequest.RequestVO> callback)
        {
            WebSocketRequest.RequestVO requestVO = null;

            GamebaseResponse.Launching.LaunchingInfo launchingInfo = Gamebase.Launching.GetLaunchingInformations();

            if (launchingInfo.launching.app.loginUrls == null ||
                string.IsNullOrEmpty(launchingInfo.launching.app.loginUrls.gamebaseUrl) == true)
            {
#if UNITY_EDITOR
                GamebaseLog.Error("You need to switch platform the Standalone.", this);
#else
                GamebaseLog.Debug("launchingInfo.launching.standalone is null.", this);
#endif
                callback(requestVO);
                return;
            }

            if (launchingInfo == null)
            {
                GamebaseLog.Debug("launchingInfo is null.", this);
                callback(requestVO);
                return;
            }

            GamebaseResponse.Launching.LaunchingInfo.GamebaseLaunching.APP.LaunchingIDPInfo launchingIDPInfo = launchingInfo.launching.app.idP["gbid"];

            if (launchingIDPInfo == null)
            {
                GamebaseLog.Debug("gbid is null.", this);
                callback(requestVO);
                return;
            }

            string clientID = launchingIDPInfo.clientId;

            StringBuilder url = new StringBuilder(launchingInfo.launching.app.loginUrls.gamebaseUrl);
            url.AppendFormat("?clientId={0}", clientID);
            url.AppendFormat("&snsCd={0}", providerName);
            url.AppendFormat("&svcUrl={0}", Uri.EscapeDataString(SCHEME_AUTH_LOGIN));
            url.AppendFormat("&tokenKind={0}", "SNS");
            url.Append("&isMobile=true");
            url.Append(MakeProviderAdditionalInfo(providerName));

            WebviewAdapterManager.Instance.ShowWebView(
                url.ToString(),
                null,
                (error) =>
            {
                callback(requestVO);
            },
                new List <string>()
            {
                SCHEME_AUTH_LOGIN,
                SCHEME_WEBVIEW_CLOSE
            },
                (scheme, error) =>
            {
                WebviewAdapterManager.SchemeInfo schemeInfo = WebviewAdapterManager.Instance.ConvertURLToSchemeInfo(scheme);

                if (schemeInfo.scheme.Equals(SCHEME_AUTH_LOGIN) == true)
                {
                    var idPAccessToken = string.Empty;
                    if (schemeInfo.parameterDictionary.TryGetValue(ACCESS_TOKEN_KEY, out idPAccessToken) == true)
                    {
                        requestVO = AuthMessage.GetIDPLoginMessage(providerName, idPAccessToken);

                        WebviewAdapterManager.Instance.CloseWebView();
                    }
                }
                else if (schemeInfo.scheme.Equals(SCHEME_WEBVIEW_CLOSE) == true)
                {
                    WebviewAdapterManager.Instance.CloseWebView();
                }
            });
        }
Beispiel #5
0
        public void Login(string providerName, Dictionary <string, object> additionalInfo, int handle)
        {
            GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> providerLoginCallback = (authToken, error) =>
            {
                if (Gamebase.IsSuccess(error) == true)
                {
                    GamebaseIndicatorReport.SetLastLoggedInInfo(providerName, authToken.member.userId);
                    GamebaseIndicatorReport.SendIndicatorData(
                        GamebaseIndicatorReportType.LogType.AUTH,
                        GamebaseIndicatorReportType.StabilityCode.GB_AUTH_LOGIN_SUCCESS,
                        GamebaseIndicatorReportType.LogLevel.INFO,
                        new Dictionary <string, string>()
                    {
                        { GamebaseIndicatorReportType.AdditionalKey.GB_SUB_CATEGORY1, GamebaseIndicatorReportType.SubCategory.LOGIN },
                        { GamebaseIndicatorReportType.AdditionalKey.GB_LOGIN_IDP, providerName },
                        { GamebaseIndicatorReportType.AdditionalKey.GB_CREDENTIAL, JsonMapper.ToJson(additionalInfo) }
                    });
                }
                else
                {
                    GamebaseIndicatorReport.SendIndicatorData(
                        GamebaseIndicatorReportType.LogType.AUTH,
                        GamebaseIndicatorReportType.StabilityCode.GB_AUTH_LOGIN_CANCELED,
                        GamebaseIndicatorReportType.LogLevel.DEBUG,
                        new Dictionary <string, string>()
                    {
                        { GamebaseIndicatorReportType.AdditionalKey.GB_SUB_CATEGORY1, GamebaseIndicatorReportType.SubCategory.LOGIN },
                        { GamebaseIndicatorReportType.AdditionalKey.GB_LOGIN_IDP, providerName },
                        { GamebaseIndicatorReportType.AdditionalKey.GB_CREDENTIAL, JsonMapper.ToJson(additionalInfo) }
                    },
                        error,
                        true);
                }

                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(handle);

                if (callback != null)
                {
                    callback(authToken, error);
                }

                GamebaseCallbackHandler.UnregisterCallback(handle);
            };

            int providerLoginHandle = GamebaseCallbackHandler.RegisterCallback(providerLoginCallback);

            if (AuthAdapterManager.Instance.IsSupportedIDP(providerName) == false)
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(providerLoginHandle);
                GamebaseErrorNotifier.FireNotSupportedAPI(
                    this,
                    callback,
                    string.Format("LoginWithAdditionalInfo({0})", providerName));
                GamebaseCallbackHandler.UnregisterCallback(providerLoginHandle);
                return;
            }

            if (CanLogin(providerLoginHandle) == false)
            {
                return;
            }

            bool hasAdapter = AuthAdapterManager.Instance.CreateIDPAdapter(providerName);

            if (hasAdapter == false)
            {
                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(providerLoginHandle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, message: GamebaseStrings.AUTH_ADAPTER_NOT_FOUND_NEED_SETUP));
                GamebaseCallbackHandler.UnregisterCallback(providerLoginHandle);
            }

            AuthAdapterManager.Instance.IDPLogin(additionalInfo, (adapterError) =>
            {
                if (Gamebase.IsSuccess(adapterError) == true)
                {
                    var idPAccessToken = AuthAdapterManager.Instance.GetIDPData <string>(providerName, AuthAdapterManager.MethodName.GET_IDP_ACCESS_TOKEN);
                    var requestVO      = AuthMessage.GetIDPLoginMessage(providerName, idPAccessToken);
                    RequestGamebaseLogin(requestVO, providerLoginHandle);

                    return;
                }

                var callback = GamebaseCallbackHandler.GetCallback <GamebaseCallback.GamebaseDelegate <GamebaseResponse.Auth.AuthToken> >(providerLoginHandle);
                if (callback == null)
                {
                    return;
                }

                GamebaseCallbackHandler.UnregisterCallback(providerLoginHandle);
                callback(null, new GamebaseError(GamebaseErrorCode.AUTH_IDP_LOGIN_FAILED, Domain, error: adapterError));
                AuthAdapterManager.Instance.IDPLogout(providerName);
            });
        }
        private void GetAccessToken(string providerName, System.Action <WebSocketRequest.RequestVO> callback)
        {
            WebSocketRequest.RequestVO requestVO = null;

            GamebaseResponse.Launching.LaunchingInfo launchingInfo = Gamebase.Launching.GetLaunchingInformations();

            if (null == launchingInfo.launching.app.loginUrls ||
                true == string.IsNullOrEmpty(launchingInfo.launching.app.loginUrls.gamebaseUrl))
            {
#if UNITY_EDITOR
                GamebaseLog.Error("You need to switch platform the Standalone.", this, "GetAccessToken");
#else
                GamebaseLog.Debug("launchingInfo.launching.standalone is null.", this, "GetAccessToken");
#endif
                callback(requestVO);
                return;
            }

            if (null == launchingInfo)
            {
                GamebaseLog.Debug("launchingInfo is null.", this, "GetAccessToken");
                callback(requestVO);
                return;
            }

            GamebaseResponse.Launching.LaunchingInfo.GamebaseLaunching.APP.LaunchingIDPInfo launchingIDPInfo = launchingInfo.launching.app.idP["gbid"];

            if (null == launchingIDPInfo)
            {
                GamebaseLog.Debug("gbid is null.", this, "GetAccessToken");
                callback(requestVO);
                return;
            }

            string clientID = launchingIDPInfo.clientId;

            StringBuilder url = new StringBuilder(launchingInfo.launching.app.loginUrls.gamebaseUrl);
            url.Append("?clientId=").Append(clientID);
            url.Append("&snsCd=").Append(providerName);
            url.Append("&svcUrl=").Append(WWW.EscapeURL(SCHEME_AUTH_LOGIN));
            url.Append("&tokenKind=").Append("SNS");

            WebviewAdapterManager.Instance.ShowWebView(
                url.ToString(),
                null,
                (error) =>
            {
                callback(requestVO);
            },
                new List <string>()
            {
                SCHEME_AUTH_LOGIN
            },
                (scheme, error) =>
            {
                WebviewAdapterManager.SchemeInfo schemeInfo = WebviewAdapterManager.Instance.ConvertURLToSchemeInfo(scheme);

                if (true == schemeInfo.parameterDictionary.ContainsKey(ACCESS_TOKEN_KEY))
                {
                    var IDPAccessToken = schemeInfo.parameterDictionary[ACCESS_TOKEN_KEY];
                    requestVO          = AuthMessage.GetIDPLoginMessage(providerName, IDPAccessToken);

                    WebviewAdapterManager.Instance.CloseWebView();
                }
            }
                );
        }