internal static void ProcessLoginResult(string result, bool wasValidating, Action <VKValidationResponse> validationCallback) { bool success = false; if (result == null) { SetAccessTokenError(new VKError { error_code = (int)VKResultCode.UserAuthorizationFailed }); } else { var tokenParams = VKUtil.ExplodeQueryString(result); if (CheckAndSetToken(tokenParams, wasValidating) == CheckTokenResult.Success) { success = true; } } if (validationCallback != null) { validationCallback(new VKValidationResponse { IsSucceeded = success }); } }
/// <summary> /// Removes active token from memory and IsolatedStorage at default key. /// </summary> public static void Logout() { Instance.AccessToken = null; VKAccessToken.RemoveTokenInIsolatedStorage(VKSDK_ACCESS_TOKEN_ISOLATEDSTORAGE_KEY); VKUtil.ClearCookies(); }
/// <summary> /// Retreive token from key-value query string /// </summary> /// <param name="urlString">String that contains URL-query part with token. E.g. access_token=eee&expires_in=0..</param> /// <returns>parsed token</returns> public static VKAccessToken FromUrlString(String urlString) { if (urlString == null) { return(null); } var args = VKUtil.ExplodeQueryString(urlString); return(TokenFromParameters(args)); }
public static void HandleProtocolLaunch(ProtocolActivatedEventArgs protocolArgs) { if (protocolArgs.Uri.OriginalString.StartsWith("vk") && protocolArgs.Uri.OriginalString.Contains("://authorize")) { var launchUriDecoded = protocolArgs.Uri.ToString(); launchUriDecoded = launchUriDecoded.Replace("authorize/#", "authorize/?"); var innerQueryParamsString = VKUtil.GetParamsOfQueryString(launchUriDecoded); VKSDK.ProcessLoginResult(innerQueryParamsString, false, null); } }
/// <summary> /// Retreive token from file. Token must be saved into file via VKAccessToken.SaveToTokenFile() /// </summary> /// <param name="filename"></param> /// <returns></returns> public static VKAccessToken TokenFromFile(String filename) { try { String data = VKUtil.FileToString(filename); return(FromUrlString(data)); } catch { return(null); } }
public override void OnCreate() { base.OnCreate(); // list the app fingerprints string[] fingerprints = VKUtil.GetCertificateFingerprint(this, PackageName); foreach (var fingerprint in fingerprints) { Console.WriteLine("Detected Fingerprint: " + fingerprint); } // setup VK tokenTracker.StartTracking(); VKSdk.Initialize(this).WithPayments(); }
/// <summary> /// Retreive token from key-value map /// </summary> /// <param name="args">Dictionary containing token info</param> /// <returns>Parsed token</returns> public static VKAccessToken TokenFromParameters(Dictionary <String, String> args) { if (args == null || args.Count == 0) { return(null); } try { var token = new VKAccessToken(); args.TryGetValue(ACCESS_TOKEN, out token.AccessToken); string expiresValue; args.TryGetValue(EXPIRES_IN, out expiresValue); int.TryParse(expiresValue, out token.ExpiresIn); args.TryGetValue(USER_ID, out token.UserId); args.TryGetValue(SECRET, out token.Secret); if (args.ContainsKey(HTTPS_REQUIRED)) { token.IsHttpsRequired = args[HTTPS_REQUIRED] == "1"; } else if (token.Secret == null) { token.IsHttpsRequired = true; } if (args.ContainsKey(CREATED)) { long.TryParse(args[CREATED], out token.Created); } else { token.Created = VKUtil.CurrentTimeMillis(); } return(token); } catch { } return(null); }
/// <summary> /// Serialize token into string /// </summary> /// <returns></returns> protected String SerializeTokenData() { var args = new Dictionary <String, Object> { { ACCESS_TOKEN, AccessToken }, { EXPIRES_IN, ExpiresIn }, { USER_ID, UserId }, { CREATED, Created } }; if (Secret != null) { args.Add(SECRET, Secret); } if (IsHttpsRequired) { args.Add(HTTPS_REQUIRED, "1"); } return(VKUtil.JoinParams(args)); }
public static bool HandleUri(Uri uri) { var tempUriStr = uri.ToString(); if (tempUriStr.StartsWith("/Protocol")) { var outerQueryParamsString = VKUtil.GetParamsOfQueryString(tempUriStr); if (!string.IsNullOrEmpty(outerQueryParamsString)) { var outerQueryParams = VKUtil.ExplodeQueryString(outerQueryParamsString); if (outerQueryParams.ContainsKey("encodedLaunchUri")) { var launchUriEncoded = outerQueryParams["encodedLaunchUri"]; var launchUriDecoded = WebUtility.UrlDecode(launchUriEncoded); if (launchUriDecoded.StartsWith("vk") && launchUriDecoded.Contains("://authorize")) { launchUriDecoded = launchUriDecoded.Replace("authorize/#", "authorize/?"); var innerQueryParamsString = VKUtil.GetParamsOfQueryString(launchUriDecoded); VKSDK.ProcessLoginResult(innerQueryParamsString, false, null); return(true); } else { // default start return(true); } } } } return(false); }
public VKRequestParameters(string methodName, params string[] parameters) { var dictParameters = VKUtil.DictionaryFrom(parameters); InitializeWith(methodName, dictParameters); }