Example #1
0
        /// <summary>
        /// Create the info section for the cast call.
        /// </summary>
        /// <returns>The infor section.</returns>
        internal XElement CreateCastCallInfoSection()
        {
            XElement content = new XElement("content",
                                            new XElement("app-id", AppIdInstance.ToString()),
                                            new XElement("hmac", "HMACSHA256"),
                                            new XElement("signing-time", DateTime.UtcNow.ToString("O"))
                                            );

            XElement outer = new XElement("outer", content);

            XmlReader reader = outer.CreateReader();

            reader.MoveToContent();
            string s = reader.ReadInnerXml();

            s = HealthVaultService.GetOuterXml(content);

            string hmac = MobilePlatform.ComputeSha256Hmac(Convert.FromBase64String(SharedSecret), s);

            XElement info = new XElement("info",
                                         new XElement("auth-info",
                                                      new XElement("app-id", AppIdInstance.ToString()),
                                                      new XElement("credential",
                                                                   new XElement("appserver2",
                                                                                new XElement("hmacSig", hmac,
                                                                                             new XAttribute("algName", "HMACSHA256")
                                                                                             ),
                                                                                content
                                                                                )
                                                                   )
                                                      )
                                         );

            return(info);
        }
Example #2
0
        /// <summary>
        /// Check that the application is authenticated.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="authenticationCompleted">Completion handler.</param>
        /// <param name="shellAuthRequired">Handler if shell authorization is required.</param>
        public static void BeginAuthenticationCheck(
            HealthVaultService service,
            EventHandler <HealthVaultResponseEventArgs> authenticationCompleted,
            EventHandler <HealthVaultResponseEventArgs> shellAuthRequired)
        {
            AuthenticationCheckState state = new AuthenticationCheckState(service, authenticationCompleted, shellAuthRequired);

            BeginAuthenticationCheck(state);
        }
Example #3
0
        /// <summary>
        /// Authorize other records.
        /// </summary>
        /// <param name="service">The HealthVaultService instance.</param>
        /// <param name="authenticationCompleted">Handler to call when finished.</param>
        /// <param name="shellAuthRequired">Handler to call for authorization.</param>
        public static void BeginAuthorizeRecords(
            HealthVaultService service,
            EventHandler <HealthVaultResponseEventArgs> authenticationCompleted,
            EventHandler <HealthVaultResponseEventArgs> shellAuthRequired)
        {
            AuthenticationCheckState state = new AuthenticationCheckState(service, authenticationCompleted, shellAuthRequired);

            state.ShellAuthRequiredHandler(null, null);
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the AuthenticationCheckState class.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="authenticationCompleted">Completion handler.</param>
 /// <param name="shellAuthRequired">Authorization required handler.</param>
 public AuthenticationCheckState(
     HealthVaultService service,
     EventHandler <HealthVaultResponseEventArgs> authenticationCompleted,
     EventHandler <HealthVaultResponseEventArgs> shellAuthRequired)
 {
     Service = service;
     AuthenticationCompletedHandler = authenticationCompleted;
     ShellAuthRequiredHandler       = shellAuthRequired;
 }
Example #5
0
        /// <summary>
        /// Process the list of authorized people and continue the flow.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        private static void GetAuthorizedPeopleCompleted(object sender, HealthVaultResponseEventArgs e)
        {
            AuthenticationCheckState state = (AuthenticationCheckState)e.Request.UserState;

            if (e.ErrorText != null)
            {
                state.AuthenticationCompletedHandler(state.Service, e);
                return;
            }

            XElement response = XElement.Parse(e.ResponseXml);

            XElement responseResults = response.Descendants("response-results").Single();

            state.Service.Records.Clear();

            foreach (XElement personInfo in responseResults.Elements("person-info"))
            {
                Guid   personId   = new Guid(personInfo.Element("person-id").Value);
                string personName = personInfo.Element("name").Value;

                // If we loaded our settings, the current record is incomplete. We will try
                // to match it to one that we got back...
                HealthVaultRecord currentRecord = state.Service.CurrentRecord;
                state.Service.CurrentRecord = null;

                foreach (XElement recordNode in personInfo.Elements("record"))
                {
                    HealthVaultRecord record = HealthVaultRecord.Create(personId, personName, HealthVaultService.GetOuterXml(recordNode));
                    if (record != null)
                    {
                        state.Service.Records.Add(record);

                        if ((currentRecord != null) &&
                            (currentRecord.PersonId == record.PersonId) &&
                            (currentRecord.RecordId == record.RecordId))
                        {
                            state.Service.CurrentRecord = record;
                        }
                    }
                }
            }

            if (state.Service.Records.Count != 0)
            {
                // all done
                state.AuthenticationCompletedHandler(state.Service, null);
            }
            else
            {
                // unsuccessful, restart from scratch...
                state.Service.ClearProvisioningInformation();
                BeginAuthenticationCheck(state);
            }
        }