Esempio n. 1
0
        private IEnumerator _Call(VKRequest httprequest)
        {
            httprequest.url = httprequest.url.Contains("?")?httprequest.url:httprequest.url + "?";
            if (string.IsNullOrEmpty(httprequest.fullurl))
            {
                if (httprequest.url.StartsWith("http"))
                {
                    httprequest.fullurl = httprequest.url;
                }
                else
                {
                    httprequest.fullurl = Utilities.GenerateFullHttpReqString(httprequest.url);
                }
            }

            if (VKToken.IsValidToken(CurrentToken))
            {
                WWW www = new WWW(httprequest.fullurl);
                yield return(www);

                HandleResponse(www, httprequest);
            }
            else
            {
                HandleTokenExpired(httprequest);
            }
        }
Esempio n. 2
0
        void Awake()
        {
            VkSetts = Resources.Load <VkSettings> ("VkSettings");
            InitToken();
            DontDestroyOnLoad(transform.gameObject);
            if (VkApiInstance == null)
            {
                VkApiInstance = this;
            }
            if (Downloader == null)
            {
                Downloader = GetComponent <Downloader> ();
            }

#if UNITY_EDITOR
            CheckEditorSetup();
#endif


            if (VKToken.IsValidToken(CurrentToken))
            {
                IsUserLoggedIn = true;
            }
            else
            {
                IsUserLoggedIn = false;
            }
        }
Esempio n. 3
0
        public static bool IsValidToken(VKToken ti)
        {
            var currentToken = ti;
            var isvalid      = currentToken.tokenRecievedTime.AddSeconds(currentToken.expires_in) > DateTime.Now
                ? true
                : false;

            return(isvalid);
        }
Esempio n. 4
0
        public void onLoggedOut()
        {
            IsUserLoggedIn = false;
            if (LoggedOut != null)
            {
                LoggedOut();
            }

            VKToken.ResetToken();
        }
Esempio n. 5
0
        public static VKToken ParseSerializeTokenFromNaviteSdk(string message)
        {
            //serialization format: token#expires_in#user_id

            string[] token = message.Split('#');
            VKToken  ti    = new VKToken();

            ti.access_token      = token[0];
            ti.tokenRecievedTime = DateTime.Now;
            ti.expires_in        = int.Parse(token[1]) == 0 ? 999999 : int.Parse(token[1]);
            ti.user_id           = token[2];
            return(ti);
        }
Esempio n. 6
0
 public void CheckEditorSetup()
 {
     if (string.IsNullOrEmpty(CurrentToken.access_token) ||
         !VKToken.IsValidToken(CurrentToken))
     {
         VkSetts.ProcessAuthUrl();
     }
     if (!VKToken.IsValidToken(CurrentToken))
     {
         Debug.LogError("Token has expired, please relogin to vk in editor");
         Debug.Break();
     }
 }
Esempio n. 7
0
 public void onReceiveNewToken(VKToken e)
 {
     CurrentToken.access_token      = e.access_token;
     CurrentToken.expires_in        = e.expires_in;
     CurrentToken.tokenRecievedTime = e.tokenRecievedTime;
     CurrentToken.user_id           = e.user_id;
     CurrentToken.Save();
     if (ReceivedNewToken != null)
     {
         ReceivedNewToken(this, e);
     }
     onLoggedIn();
     Debug.Log("New token is" + e.access_token);
 }
        public void ReceiveNewTokenMessage(string message)
        {
            var token = VKToken.ParseSerializeTokenFromNaviteSdk(message);

            vkapi.onReceiveNewToken(token);
        }
Esempio n. 9
0
 void InitToken()
 {
     CurrentToken = VKToken.LoadPersistent();
 }