Example #1
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();
                }
            });
        }
        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();
                }
            }
                );
        }