Esempio n. 1
0
        public void SignUp(OnAuthorizationSuccessDelegate OnSuccessDelegate, OnAuthorizationFailedDelegate OnFailedDelegate, bool forceExternalBrowser = false)
        {
            string url = QUARTERS_URL + "/guest?token=" + session.GuestToken + "&redirect_uri=" + URL_SCHEME + "&inline=trueresponse_type=code&client_id=" + QuartersInit.Instance.APP_ID;

            this.OnAuthorizationSuccess = OnSuccessDelegate;
            this.OnAuthorizationFailed  = OnFailedDelegate;

            if (Application.isEditor && forceExternalBrowser)
            {
                //spawn editor UI
                Instantiate <GameObject>(Resources.Load <GameObject>("QuartersEditor"));

                Application.OpenURL(url);
            }
            else
            {
                //direct to the browser
                if (!forceExternalBrowser)
                {
                    //web view authentication
                    QuartersWebView.OpenURL(url);
                    QuartersWebView.OnDeepLink = DeepLink;
                }
                else
                {
                    //external authentication
                    Application.OpenURL(url);
                }
            }
        }
Esempio n. 2
0
        public static QuartersWebView OpenURL(string url)
        {
            //UniWebViewLogger.Instance.LogLevel = UniWebViewLogger.Level.Verbose;

            Debug.Log("Web view open url: " + url);

            GameObject      webViewGO       = new GameObject("QuartersWebView");
            QuartersWebView quartersWebView = webViewGO.AddComponent <QuartersWebView>();

            UniWebView webView = webViewGO.AddComponent <UniWebView>();

            SetFrameSize(webView);

            webView.Load(url);
            webView.Show(false, UniWebViewTransitionEdge.Bottom);


            webView.OnPageStarted += (UniWebView view, string u) => {
                Debug.Log("OnPageStarted " + u);
                if (u.IsDeepLink())
                {
                    //deep link opened
                    if (OnDeepLink != null)
                    {
                        OnDeepLink(u, isExternalBrowser: false);
                    }
                    webView.Hide(false);
                }
                else
                {
                    if (u != url)
                    {
                        //external link, open external browser instead and invalidate this webview
                        webView.Stop();
                        webView.Hide();
                        Application.OpenURL(u);
                    }
                }
            };


            //handle autorotation
            webView.OnOreintationChanged += (view, orientation) => {
                SetFrameSize(webView);
            };

            webView.OnShouldClose += ShouldClose;


            return(quartersWebView);
        }
Esempio n. 3
0
        private void AuthorizeExternal(bool forceExternalBrowser = false)
        {
            Debug.Log("OAuth authorization");

            string url = QUARTERS_URL + "/oauth/authorize?response_type=code&client_id=" + QuartersInit.Instance.APP_ID + "&redirect_uri=" + URL_SCHEME + "&inline=true";

            Debug.Log(url);


            if (!forceExternalBrowser)
            {
                //web view authentication
                QuartersWebView.OpenURL(url);
                QuartersWebView.OnDeepLink = DeepLink;
            }
            else
            {
                //external authentication
                Application.OpenURL(url);
            }
        }
Esempio n. 4
0
        public void Init(Action OnInitComplete, Action <string> OnInitError)
        {
            Debug.Log("Quarters Init:");

            string error = "";

            if (string.IsNullOrEmpty(APP_ID))
            {
                Debug.LogError("Quarters App Id is empty");
            }
            if (string.IsNullOrEmpty(APP_KEY))
            {
                Debug.LogError("Quarters App key is empty");
            }


            GameObject quarters = new GameObject("Quarters");

            quarters.transform.SetParent(this.transform);
            DontDestroyOnLoad(quarters.gameObject);

            Quarters quartersComponent = quarters.AddComponent <Quarters>();

            quartersComponent.Init();

            GameObject quartersWebView = new GameObject("QuartersWebView");

            quarters.transform.SetParent(this.transform);
            QuartersWebView webViewComponent = quarters.AddComponent <QuartersWebView>();

            quartersComponent.QuartersWebView = webViewComponent;
            webViewComponent.Init();
            DontDestroyOnLoad(quartersWebView.gameObject);


            Debug.Log("QuartersInit complete");
            QuartersInit.OnInitComplete?.Invoke();
            OnInitComplete?.Invoke();
        }
Esempio n. 5
0
        private IEnumerator CreateTransferRequestCall(TransferAPIRequest request, bool forceExternalBrowser = false)
        {
            if (Application.isEditor && forceExternalBrowser)
            {
                Debug.LogWarning("Quarters: Transfers with external browser arent supported in Unity editor");
            }

            Debug.Log("CreateTransferRequestCall");

            Dictionary <string, string> headers = new Dictionary <string, string>(AuthorizationHeader);

            headers.Add("Authorization", "Bearer " + session.AccessToken);


            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("tokens", request.tokens);
            if (!string.IsNullOrEmpty(request.description))
            {
                data.Add("description", request.description);
            }
            data.Add("app_id", QuartersInit.Instance.APP_ID);


            string dataJson = JsonConvert.SerializeObject(data);

            Debug.Log(dataJson);
            byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(dataJson);


            WWW www = new WWW(API_URL + "/requests", dataBytes, headers);

            Debug.Log(www.url);

            while (!www.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);

                request.failedDelegate("Creating transfer failed: " + www.error);
            }
            else
            {
                Debug.Log(www.text);

                string response = www.text;
                Debug.Log("Response: " + response);

                TransferRequest transferRequest = new TransferRequest(response);

                request.requestId = transferRequest.id;
                Debug.Log("request id is: " + transferRequest.id);
                currentTransferAPIRequests.Add(request);

                //continue outh forward
                string url = QUARTERS_URL + "/requests/" + transferRequest.id + "?inline=true" + "&redirect_uri=" + URL_SCHEME;

                if (!forceExternalBrowser)
                {
                    //web view authentication
                    QuartersWebView.OpenURL(url);
                    QuartersWebView.OnDeepLink = DeepLink;
                }
                else
                {
                    //external authentication
                    Application.OpenURL(url);
                }
            }
        }