Ejemplo n.º 1
0
        /// <summary>
        /// Starts authorization process. Opens and requests for access if VK App is installed.
        /// Otherwise SDK will navigate current app to SDK navigation page and start OAuth in WebBrowser.
        /// </summary>
        /// <param name="scopeList">List of permissions for your app</param>
        /// <param name="revoke">If true user will be allowed to logout and change user</param>
        /// <param name="forceOAuth">SDK will use only OAuth authorization via WebBrowser</param>
        public static void Authorize(List <String> scopeList, bool revoke = false, bool forceOAuth = false,
                                     LoginType loginType = LoginType.WebView)
        {
            try
            {
                CheckConditions();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                return;
            }

            if (scopeList == null)
            {
                scopeList = new List <string>();
            }

            // Force OFFLINE scope using
            if (!scopeList.Contains(VKScope.OFFLINE))
            {
                scopeList.Add(VKScope.OFFLINE);
            }


            switch (loginType)
            {
            case LoginType.VKApp:
#if SILVERLIGHT
#if DEBUG
                MessageBox.Show("Currently only the webview authentication is supported for Silverlight apps.");
#endif

                // do not currently support vk app authorization
                RootFrame.Navigate(new Uri(string.Format(VK_NAVIGATE_STR_FRM, string.Join(",", scopeList), revoke), UriKind.Relative));
#else
                AuthorizeVKApp(scopeList, revoke);
#endif
                break;

            default:
#if SILVERLIGHT
                RootFrame.Navigate(new Uri(string.Format(VK_NAVIGATE_STR_FRM, string.Join(",", scopeList), revoke), UriKind.Relative));
#else
                var loginUserControl = new VKLoginUserControl();

                loginUserControl.Scopes = scopeList;
                loginUserControl.Revoke = revoke;

                loginUserControl.ShowInPopup(Windows.UI.Xaml.Window.Current.Bounds.Width,
                                             Windows.UI.Xaml.Window.Current.Bounds.Height);
#endif
                break;
            }
        }
Ejemplo n.º 2
0
        internal static void InvokeValidationRequest(VKValidationRequest request, Action <VKValidationResponse> callback)
        {
            VKExecute.ExecuteOnUIThread(() =>
            {
#if SILVERLIGHT
                VKParametersRepository.SetParameterForId("ValidationCallback", callback);
                RootFrame.Navigate(new Uri(string.Format("/VK.WindowsPhone.SDK;component/Pages/VKLoginPage.xaml?ValidationUri={0}", HttpUtility.UrlEncode(request.ValidationUri)), UriKind.Relative));
#else
                var loginUserControl = new VKLoginUserControl();

                loginUserControl.ValidationUri      = request.ValidationUri;
                loginUserControl.ValidationCallback = callback;

                loginUserControl.ShowInPopup(Windows.UI.Xaml.Window.Current.Bounds.Width,
                                             Windows.UI.Xaml.Window.Current.Bounds.Height);
#endif
            });
        }