public LoginWindowViewModel(ILiveService liveAuthService, IConfigurationService configurationService)
        {
            if (liveAuthService == null)
                throw new ArgumentNullException("liveAuthService");

            if (configurationService == null)
                throw new ArgumentNullException("configurationService");

            _liveAuthService = liveAuthService;
            _configurationService = configurationService;

            Loaded = new RelayCommand(() =>
            {
                var loginUrl = _liveAuthService.GetLoginUrl();
                this.CurrentPage = new Uri(loginUrl, UriKind.Absolute);
            });

            Navigated = new RelayCommand<NavigationEventArgs>((args) =>
            {
                if (args.Uri.AbsoluteUri.StartsWith("https://login.live.com/oauth20_desktop.srf"))
                {
                    var continueProcessing = false;
                    var parsedQueryParameters = HttpUtility.ParseQueryString(args.Uri.Query);
                    var authorizationCode = parsedQueryParameters["code"];

                    if (authorizationCode != null)
                    {
                        _liveAuthService.GetTokens(authorizationCode);
                        continueProcessing = true;
                    }

                    Messenger.Default.Send<CloseLoginWindow>(new CloseLoginWindow(continueProcessing));
                }
            });
        }
Example #2
0
        public LoginWindowViewModel(ILiveService liveAuthService, IConfigurationService configurationService)
        {
            if (liveAuthService == null)
            {
                throw new ArgumentNullException("liveAuthService");
            }

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

            _liveAuthService      = liveAuthService;
            _configurationService = configurationService;

            Loaded = new RelayCommand(() =>
            {
                var loginUrl     = _liveAuthService.GetLoginUrl();
                this.CurrentPage = new Uri(loginUrl, UriKind.Absolute);
            });

            Navigated = new RelayCommand <NavigationEventArgs>((args) =>
            {
                if (args.Uri.AbsoluteUri.StartsWith("https://login.live.com/oauth20_desktop.srf"))
                {
                    var continueProcessing    = false;
                    var parsedQueryParameters = HttpUtility.ParseQueryString(args.Uri.Query);
                    var authorizationCode     = parsedQueryParameters["code"];

                    if (authorizationCode != null)
                    {
                        _liveAuthService.GetTokens(authorizationCode);
                        continueProcessing = true;
                    }

                    Messenger.Default.Send <CloseLoginWindow>(new CloseLoginWindow(continueProcessing));
                }
            });
        }