public static UnityConnectConsentView ShowUnityConnectConsentView(string URL)
        {
            UnityConnectConsentView unityConnectConsentView = ScriptableObject.CreateInstance <UnityConnectConsentView>();
            Rect position = new Rect(100f, 100f, 800f, 605f);

            unityConnectConsentView.titleContent     = EditorGUIUtility.TrTextContent("Unity Application Consent Window", null, null);
            unityConnectConsentView.minSize          = new Vector2(position.width, position.height);
            unityConnectConsentView.maxSize          = new Vector2(position.width, position.height);
            unityConnectConsentView.position         = position;
            unityConnectConsentView.m_InitialOpenURL = URL;
            unityConnectConsentView.ShowModal();
            unityConnectConsentView.m_Parent.window.m_DontSaveToLayout = true;
            return(unityConnectConsentView);
        }
Ejemplo n.º 2
0
        public static UnityConnectConsentView ShowUnityConnectConsentView(String URL)
        {
            UnityConnectConsentView consentView = ScriptableObject.CreateInstance <UnityConnectConsentView>();

            var rect = new Rect(100, 100, 800, 605);

            consentView.titleContent     = EditorGUIUtility.TrTextContent("Unity Application Consent Window");
            consentView.minSize          = new Vector2(rect.width, rect.height);
            consentView.maxSize          = new Vector2(rect.width, rect.height);
            consentView.position         = rect;
            consentView.m_InitialOpenURL = URL;
            consentView.ShowModal();

            consentView.m_Parent.window.m_DontSaveToLayout = true;

            return(consentView);
        }
        public static void GetAuthorizationCodeAsync(string clientId, Action <AuthCodeResponse> callback)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId is null or empty.", "clientId");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if (string.IsNullOrEmpty(UnityConnect.instance.GetAccessToken()))
            {
                throw new InvalidOperationException("User is not logged in or user status invalid.");
            }

            string url = string.Format("{0}/v1/oauth2/authorize", UnityConnect.instance.GetConfigurationURL(CloudConfigUrl.CloudIdentity));

            AsyncHTTPClient client = new AsyncHTTPClient(url);

            client.postData = string.Format("client_id={0}&response_type=code&format=json&access_token={1}&prompt=none",
                                            clientId,
                                            UnityConnect.instance.GetAccessToken());
            client.doneCallback = delegate(AsyncHTTPClient c)
            {
                AuthCodeResponse response = new AuthCodeResponse();
                if (!c.IsSuccess())
                {
                    response.Exception = new InvalidOperationException("Failed to call Unity ID to get auth code.");
                }
                else
                {
                    try
                    {
                        var json = new JSONParser(c.text).Parse();
                        if (json.ContainsKey("code") && !json["code"].IsNull())
                        {
                            response.AuthCode = json["code"].AsString();
                        }
                        else if (json.ContainsKey("message"))
                        {
                            response.Exception = new InvalidOperationException(string.Format("Error from server: {0}", json["message"].AsString()));
                        }
                        else if (json.ContainsKey("location") && !json["location"].IsNull())
                        {
                            UnityConnectConsentView consentView = UnityConnectConsentView.ShowUnityConnectConsentView(json["location"].AsString());
                            if (!string.IsNullOrEmpty(consentView.Code))
                            {
                                response.AuthCode = consentView.Code;
                            }
                            else if (!string.IsNullOrEmpty(consentView.Error))
                            {
                                response.Exception = new InvalidOperationException(string.Format("Error from server: {0}", consentView.Error));
                            }
                            else
                            {
                                response.Exception = new InvalidOperationException("Consent Windows was closed unexpected.");
                            }
                        }
                        else
                        {
                            response.Exception = new InvalidOperationException("Unexpected response from server.");
                        }
                    }
                    catch (JSONParseException)
                    {
                        response.Exception = new InvalidOperationException("Unexpected response from server: Failed to parse JSON.");
                    }
                }

                callback(response);
            };
            client.Begin();
        }