Inheritance: IOnlineIdAuthenticator
コード例 #1
0
        /// <summary>
        /// Creates a new TailoredAuthClient class.
        /// </summary>
        /// <param name="authClient">The LiveAuthClient instance.</param>
        public TailoredAuthClient(LiveAuthClient authClient)
        {
            Debug.Assert(authClient != null, "authClient cannot be null.");

            this.authClient = authClient;
            this.authenticator = new OnlineIdAuthenticator();
        }
        public Scenario02_JwtToken()
        {
            this.InitializeComponent();

            _authenticator = new OnlineIdAuthenticator();

            PromptType = CredentialPromptType.PromptIfNeeded;
            SignInOptions.SelectedItem = PromptIfNeeded;

            NeedsToGetTicket = true;
            SignOutButton.Visibility = CanSignOut ? Visibility.Visible : Visibility.Collapsed;
        }
コード例 #3
0
ファイル: LiveConnection.cs プロジェクト: nghia2080/CProject
        /// <summary>
        /// Create connection with scope Basic, SkyDrive.
        /// </summary>
        /// <returns>Return true if connect successful. Otherwise, return false.</returns>
        public async Task<bool> CreateConnectionAsync()
        {
            if (AccessToken != null)
            {
                return true;
            }

            try
            {
                var targetArray = new List<OnlineIdServiceTicketRequest>
                                      {
                                          new OnlineIdServiceTicketRequest("wl.basic wl.signin wl.contacts_photos",
                                                                           "DELEGATION")
                                      };

                _authenticator = new OnlineIdAuthenticator();

                var promptType = (ApplicationData.Current.LocalSettings.Values["UserFirstName"] + string.Empty != string.Empty) ? CredentialPromptType.PromptIfNeeded : CredentialPromptType.RetypeCredentials;


                var result = await _authenticator.AuthenticateUserAsync(targetArray, promptType);

                if (result.Tickets[0].Value != string.Empty)
                {
                    AccessToken = result.Tickets[0].Value;
                    return true;
                }
                else
                {
                    // errors are to be handled here.
                    return false;
                }
                //var loginResult = await _auth.LoginAsync(new[] { "wl.basic, wl.logout" });

                //if (loginResult.Status == LiveConnectSessionStatus.Connected)
                //{
                //    _liveConnectClient = new LiveConnectClient(loginResult.Session);
                //    eSECID = ApplicationData.Current.RoamingSettings.Values[ESEC_ID] + string.Empty;

                //    return true;
                //}

                //return false;
            }
            catch
            {
                return false;
            }
        }
コード例 #4
0
 public OnlineIdAuthenticationProvider(ServiceInfo serviceInfo)
     : base(serviceInfo)
 {
     this.authenticator = new OnlineIdAuthenticator();
 }
        public async Task<AuthResult> AuthAsync(string startUrl, string endUrlPrefix)
        {
            AuthResult result = new AuthResult(WebAuthenticationStatus.UserCancel);
            Uri start = null;

            OnlineIdServiceTicketRequest[] tickets = new OnlineIdServiceTicketRequest[]
            {
                new OnlineIdServiceTicketRequest(
                    new Uri(startUrl).Host,
                    String.IsNullOrEmpty(LiveIdAuthPolicy)
                        ? ServiceDefinition.DefaultLiveIdAuthPolicy
                        : LiveIdAuthPolicy)
            };

            try
            {
                var onlineIdAuthenticator = new OnlineIdAuthenticator();
                UserIdentity useridentity =
                    await onlineIdAuthenticator.AuthenticateUserAsync(tickets, CredentialPromptType.PromptIfNeeded);

                if (useridentity != null && useridentity.Tickets != null && useridentity.Tickets.Count > 0)
                {
                    OnlineIdServiceTicket ticket = useridentity.Tickets.First();
                    start = new Uri(startUrl + WebUtility.UrlEncode("&" + ticket.Value) + "&mobile=true");
                }
            }
            catch (TaskCanceledException)
            {
                result.Status = WebAuthenticationStatus.UserCancel;
            }
            catch
            {
                start = new Uri(startUrl + "&mobile=true");
            }
            
            if (start != null)
            {
                WebAuthenticationResult webAuthResult = (await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, start, new Uri(endUrlPrefix)));
                result = new AuthResult(webAuthResult);
            }

            return result;
        }
コード例 #6
0
ファイル: SecurityManager.cs プロジェクト: pglazkov/Linqua
        private static async Task<MobileServiceUser> DoLoginAsync(CredentialPromptType promptType)
        {
            MobileServiceUser user = null;
            var authenticator = new OnlineIdAuthenticator();
            var mobileServicesTicket = new OnlineIdServiceTicketRequest("wl.signin", "DELEGATION");

            var ticketRequests = new List<OnlineIdServiceTicketRequest> {mobileServicesTicket};

            var authResult = await authenticator.AuthenticateUserAsync(ticketRequests, promptType);

            if ((authResult.Tickets.Count == 1) && (authResult.Tickets[0].ErrorCode == 0))
            {
                var accessToken = authResult.Tickets[0];

                var payload = new JObject
                {
                    ["access_token"] = accessToken.Value
                };

                user = await MobileService.Client.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, payload);

                LegacyUserId.Value = authResult.SafeCustomerId;
            }

            return user;
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: robledop/Demos-20485
		public MainPage()
		{
			InitializeComponent();

			_authenticator = new OnlineIdAuthenticator();
		}