Beispiel #1
0
        private void Authorize(List <Scope> scopes, Action OnSuccess, Action <string> OnError)
        {
            session = new Session();


            if (IsAuthorized)
            {
                StartCoroutine(GetAccessToken(delegate {
                    OnSuccess?.Invoke();
                }, delegate(string error) {
                    OnError?.Invoke(error);
                }));

                return;
            }


            string redirectSafeUrl = UnityWebRequest.EscapeURL(URL_SCHEME);

            string scopeString = "";

            foreach (Scope scope in scopes)
            {
                scopeString += scope.ToString();
                if (scopes.IndexOf(scope) != scopes.Count - 1)
                {
                    scopeString += " ";
                }
            }

            string url = BASE_URL + "/oauth2/authorize?response_type=code&client_id="
                         + QuartersInit.Instance.APP_ID + "&redirect_uri="
                         + redirectSafeUrl
                         + $"&scope={UnityWebRequest.EscapeURL(scopeString)}"
                         + $"&code_challenge_method=S256"
                         + $"&code_challenge={PCKE.CodeChallenge()}";

            Debug.Log(url);

            //web view authentication
            QuartersWebView.OpenURL(url, LinkType.External);
            QuartersWebView.OnDeepLink = delegate(QuartersLink link) {
                if (link.QueryString.ContainsKey("code"))
                {
                    string code = link.QueryString["code"];
                    StartCoroutine(GetRefreshToken(code, OnSuccess, OnError));
                    QuartersWebView.OnDeepLink = null;
                }
                else if (link.QueryString.ContainsKey("error"))
                {
                    OnError?.Invoke(link.QueryString["error"]);
                    QuartersWebView.OnDeepLink = null;
                }
            };
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #4
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);
                }
            }
        }