Exemplo n.º 1
0
        private void RegisterDevice_OnClicked(object sender, EventArgs e)
        {
            var currentDeviceId = CrossDeviceInfo.Current.Id;
            var deviceModel     = CrossDeviceInfo.Current.Model;
            var devicePlatform  = CrossDeviceInfo.Current.Platform;
            var devieVersion    = CrossDeviceInfo.Current.Version;

            var baseURL = "http://meruapi.meru.info/api/DeviceApi/RegisterDevice?UserId=" + MedInFHIR.App.userId + "&DeviceId=" + currentDeviceId;

            var reesult = RegisterDeviceApi(baseURL).Result;

            if (reesult != "Error")
            {
                RegisterDeviceModel bsObj = JsonConvert.DeserializeObject <RegisterDeviceModel>(reesult);


                MedInFHIR.App.clientId     = bsObj.ClientId;
                MedInFHIR.App.clientSecret = bsObj.ClientSecret;
                MedInFHIR.App.deviceId     = currentDeviceId;

                clientId.Text     = bsObj.ClientId;
                clientSecret.Text = bsObj.ClientSecret;
            }
            else
            {
                lblError.Text = "Error" + errorMessage;
            }

            var deviceInfo = "Device Id: " + currentDeviceId + "\n" + "Device Model: " + deviceModel + "\n" + "Device platform: " + devicePlatform + "\n" + "Device Version: " + devieVersion;

            deviceDetails.Text = deviceInfo;
        }
Exemplo n.º 2
0
        public IHttpActionResult UnRegisterDevice(RegisterDeviceModel model)
        {
            var user = userRepository.GetById(model.UserId);

            user.DeviceToken = null;

            userRepository.Update(user);
            unitofWork.SaveChanges();
            return(Ok(user));
        }
Exemplo n.º 3
0
        public IActionResult RegisterDevice(RegisterDeviceModel model)
        {
            if (model == null || string.IsNullOrEmpty(model.AppId) || string.IsNullOrEmpty(model.Challenge) || string.IsNullOrEmpty(model.RawRegisterResponse))
            {
                return(BadRequest(new { error = "Invalid Data", code = 400 }));
            }

            try
            {
                var device = App.CurrentUser.Devices.FirstOrDefault(x => x.Name.Equals(model.DeviceName));

                if (device != null)
                {
                    return(BadRequest(new { error = "This name already used on another device.", code = 400 }));
                }

                var u2F = new FidoUniversalTwoFactor();

                App.Registrations.TryGetValue(model.Challenge, out var startedRegistration);

                if (startedRegistration == null)
                {
                    return(BadRequest(new { error = "Invalid Started Registration.", code = 400 }));
                }

                var facetIds = new List <FidoFacetId> {
                    new FidoFacetId(startedRegistration.AppId.ToString())
                };
                var deviceRegistration = u2F.FinishRegistration(startedRegistration, model.RawRegisterResponse, facetIds);

                if (deviceRegistration == null)
                {
                    return(BadRequest(new { error = "Invalid Device Registration.", code = 400 }));
                }

                App.AddDeviceRegistration(model.DeviceName, deviceRegistration);
                App.Registrations.Remove(model.Challenge);

                return(Ok(new { message = "Device has been registered.", code = 200, redirect = Url.Action("CurrentUser") }));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                return(BadRequest(new { error = exception.Message, code = 500 }));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult RegisterDevice(RegisterDeviceModel model)
        {
            var user = userRepository.GetById(model.UserId);

            //if (user.DeviceToken != null && user.DeviceToken != string.Empty)
            //{
            //    if (!user.DeviceToken.Contains(model.DeviceToken))
            //        if (user.DeviceToken.Length > 200)
            //            user.DeviceToken = model.DeviceToken;
            //        else
            //            user.DeviceToken = user.DeviceToken + "," + model.DeviceToken;
            //}
            //else
            user.DeviceToken = model.DeviceToken;

            userRepository.Update(user);
            unitofWork.SaveChanges();
            return(Ok(user));
        }
Exemplo n.º 5
0
        public RegisterDeviceModel GetRegistrationModel()
        {
            var u2F = new FidoUniversalTwoFactor();
            var startedRegistration = u2F.StartRegistration(AppId);

            var model = new RegisterDeviceModel
            {
                AppId     = startedRegistration.AppId.ToString(),
                Challenge = startedRegistration.Challenge
            };

            if (App.CurrentUser.Devices.Any())
            {
                model.RegisteredKeys.AddRange(App.CurrentUser.Devices.Select(x => x.Identifier).ToList());
            }

            App.AddRegistration(model.Challenge, startedRegistration);
            return(model);
        }