Exemplo n.º 1
0
        /**
         * Retrieve token from key-value map
         *
         * @param parameters map that contains token info
         * @return Parsed token
         */
        public static VKAccessToken TokenFromParameters(Dictionary<string, string> parameters)
        {
            if (parameters == null || parameters.Count == 0)
                return null;

            var token = new VKAccessToken();
            token.accessToken = parameters[ACCESS_TOKEN];
            token.expiresIn = Convert.ToInt32(parameters[EXPIRES_IN]);
            token.userId = parameters[USER_ID];
            //token.secret = parameters[SECRET];
            token.httpsRequired = false;

            if (parameters.ContainsKey(HTTPS_REQUIRED))
            {
                token.httpsRequired = parameters[HTTPS_REQUIRED] == "1";
            }
            if (parameters.ContainsKey(CREATED))
            {
                token.created = Convert.ToInt64(parameters[CREATED]);
            }
            else
            {
                token.created = DateTime.Now.Millisecond;
            }
            return token;
        }
Exemplo n.º 2
0
 private string GenerateSig(VKAccessToken token)
 {
     //Read description here https://vk.com/dev/api_nohttps
     //At first, we need key-value pairs in order of request
     string querystring = VKstringJoiner.joinParams(mPreparedParameters);
     //Then we generate "request string" /method/{METHOD_NAME}?{GET_PARAMS}{POST_PARAMS}
     querystring = string.Format("/method/{0}?{1}", methodName, querystring);
     return VKUtil.md5(querystring + token.secret);
 }
Exemplo n.º 3
0
Arquivo: VKSdk.cs Projeto: NGWeb/VkApi
 /**
  * Initialize SDK with responder for global SDK events and custom token key
  * (e.g., saved from other source or for some test reasons)
  *
  * @param listener responder for global SDK events
  * @param appId    your application id (if you haven't, you can create standalone application here https://vk.com/editapp?act=create )
  * @param token    custom-created access token
  */
 public static void initialize(string appId, VKAccessToken token)
 {
     initialize(appId);
     sInstance.Value.mAccessToken = token;
     sInstance.Value.performTokenCheck(token, true);
 }
Exemplo n.º 4
0
Arquivo: VKSdk.cs Projeto: NGWeb/VkApi
 private bool performTokenCheck(VKAccessToken token, bool isUserToken)
 {
     if (token != null)
     {
         if (token.IsExpired())
         {
             mListener.onTokenExpired(token);
         }
         else if (token.accessToken != null)
         {
             //           if (isUserToken) mListener.onAcceptUserToken(token);
             return true;
         }
         else
         {
             VKError error = new VKError(VKError.VK_API_CANCELED);
             error.errorMessage = "User token is invalid";
             mListener.onAccessDenied(error);
         }
     }
     return false;
 }
Exemplo n.º 5
0
Arquivo: VKSdk.cs Projeto: NGWeb/VkApi
 public static bool wakeUpSession(VKAccessToken token)
 {
     if (sInstance.Value.performTokenCheck(token, false))
     {
         sInstance.Value.mAccessToken = token;
         return true;
     }
     return false;
 }
Exemplo n.º 6
0
Arquivo: VKSdk.cs Projeto: NGWeb/VkApi
        /**
         * Set API token to passed
         *
         * @param token token must be used for API requests
         * @param renew flag indicates token renewal
         */
        public static void setAccessToken(VKAccessToken token, bool renew)
        {
            sInstance.Value.mAccessToken = token;

            if (sInstance.Value.mListener != null)
            {
                if (!renew)
                {
                    sInstance.Value.mListener.onReceiveNewToken(token);
                }
                else
                {
                    sInstance.Value.mListener.onRenewAccessToken(token);
                }
            }
        }