Esempio n. 1
1
        async void Handle_Clicked(object sender, System.EventArgs e)
        {
            var x = new CloudData();

            GraphUser y = await x.GetDisplayName();


            Task <string> access_id = x.GetAccessID();

            System.Diagnostics.Debug.WriteLine("Debug: get access ID " + access_id.Result);

            //await DisplayAlert("Alert", "Welcome, " + y, "OK");

            var displayName = new Item
            {
                Name    = "Logged in as: " + y.displayName,
                Company = "Company: " + y.Company,
                Stand   = "Stand number: " + y.StandID
            };

            App.Current.Properties["LoginName"]   = "Logged in as: " + y.displayName;
            App.Current.Properties["StandName"]   = "Stand ID: " + y.StandID;
            App.Current.Properties["CompanyName"] = "Company: " + y.Company;



            await App.Current.SavePropertiesAsync();

            var Scanner = new Scanner.Scanner();

            Scanner.BindingContext = displayName;


            Application.Current.MainPage = Scanner;
        }
Esempio n. 2
0
        private async void UserChangedWorkAddress(GraphUser user)
        {
            try
            {
                if (user == null)
                {
                    return;
                }

                var employee = (await _dataService.GetAllEmployeesAsync())
                               .FirstOrDefault(e => e.Email.Equals(user.UserPrincipalName));

                if (employee != null)
                {
                    employee.WorkAddress   = user.WorkAddress;
                    employee.WorkLatitude  = user.WorkLatitude.HasValue ? user.WorkLatitude.Value : default(double);
                    employee.WorkLongitude = user.WorkLongitude.HasValue ? user.WorkLongitude.Value : default(double);
                    await _dataService.InsertOrUpdateEmployeeAsync(employee);
                }
            }
            catch (Exception ex)
            {
                if (!IsConnected)
                {
                    await _dialogService.ShowAlertAsync("No network connection, please check your internet.", "Service unavailable", "Ok");
                }
                Debug.WriteLine($"[UserChangedHomeAddress] Error updating in: {ex}");
            }
        }
Esempio n. 3
0
        private async void UpdateDriverTimeRange(GraphUser user)
        {
            try
            {
                if (user == null)
                {
                    return;
                }

                var driver = (await _dataService.GetAllDriversAsync())
                             .FirstOrDefault(u => u.Name.Equals(user.UserPrincipalName));

                if (driver != null)
                {
                    driver.Arrival   = user.ArrivalTime;
                    driver.Departure = user.DepartureTime;
                    await _dataService.InsertOrUpdateDriverAsync(driver);
                }
            }
            catch (Exception ex)
            {
                if (!IsConnected)
                {
                    await _dialogService.ShowAlertAsync("No network connection, please check your internet.", "Service unavailable", "Ok");
                }
                Debug.WriteLine($"[UpdateEmployeeTimeRange] Error updating in: {ex}");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the FBUser class from a GraphUser
        /// </summary>
        public FBUser(GraphUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.Id         = user.Id;
            this.Name       = user.Name;
            this.UserName   = user.UserName;
            this.FirstName  = user.FirstName;
            this.MiddleName = user.MiddleName;
            this.LastName   = user.LastName;
            this.Birthday   = user.Birthday;
            if (user.Location == null)
            {
                this.Location = null;
            }
            else
            {
                this.Location = new FBLocation(user.Location);
            }
            this.Link = user.Link;
            this.ProfilePictureUrl = user.ProfilePictureUrl;
        }
Esempio n. 5
0
        private async Task <bool> UpdateSettingsAsync(GraphUser user, Employee employee)
        {
            var drivers = await _dataService.GetAllDriversAsync();

            var driver = drivers.FirstOrDefault(d =>
                                                !string.IsNullOrEmpty(d.Name) && d.Name.Equals(user.UserPrincipalName));

            if (driver != null)
            {
                App.CurrentUser.ArrivalTime   = driver.Arrival;
                App.CurrentUser.DepartureTime = driver.Departure;
                App.CurrentUser.RiderRequests = DriverHelper.GetRiderRequests(driver).Count();
                Settings.DriverEnabled        = true;
            }
            else
            {
                Settings.DriverEnabled = false;
            }

            // Any changes since last login? delta query
            if (string.IsNullOrEmpty(Settings.DeltaLink))
            {
                // First login, fetch actual delta state
                Settings.DeltaLink = await _userService.InitializeDeltaQueryAsync();
            }
            else
            {
                // Check changes from last login
                var userChanges = await _userService.GetDeltaQueryChangesAsync(Settings.DeltaLink);

                return(await _userHelper.UpdateProfilesChanges(userChanges, employee));
            }

            return(false);
        }
Esempio n. 6
0
        private async void OnSignInOrOut()
        {
            // EEP, cheesy!!
            if (_signInButtonText == SIGN_IN)
            {
                StatusMessage     = "Signing in";
                SignInButtonText  = SIGN_OUT;
                SignInButtonColor = new SolidColorBrush(Colors.Red);

                if (_officeGraphClient.Initialize())
                {
                    OnReload();
                }
            }
            else
            {
                StatusMessage     = "Signing out..";
                SignInButtonText  = SIGN_IN;
                SignInButtonColor = new SolidColorBrush(Colors.Green);
                await _officeGraphClient.SignOut();

                _me           = null; AnnounceProperty(nameof(Me));
                _myImageBytes = null; AnnounceProperty(nameof(MyImage));
            }
            StatusMessage = "Ok";
        }
        /// <summary>
        /// Handles the page load event
        /// </summary>
        /// <param name="sender">
        /// Sender object
        /// </param>
        /// <param name="e">
        /// Event args
        /// </param>
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            var session = SessionStorage.Load();

            if (null != session)
            {
                this.ExpiryText.Text = string.Format("Login expires on: {0}", session.Expires.ToString());

                this.ProgressText      = "Fetching details from Facebook...";
                this.ProgressIsVisible = true;

                try
                {
                    var fb = new FacebookClient(session.AccessToken);

                    dynamic result = await fb.GetTaskAsync("me");

                    var user = new GraphUser(result);
                    user.ProfilePictureUrl = new Uri(string.Format("https://graph.facebook.com/{0}/picture?access_token={1}", user.Id, session.AccessToken));

                    this.CurrentUser = user;

                    await this.GetUserStatus(fb);
                }
                catch (FacebookOAuthException exception)
                {
                    MessageBox.Show("Error fetching user data: " + exception.Message);
                }

                this.ProgressText      = string.Empty;
                this.ProgressIsVisible = false;
            }
        }
Esempio n. 8
0
        private async void UpdateEmployeeTimeRange(GraphUser user)
        {
            try
            {
                if (user == null)
                {
                    return;
                }

                var employee = (await _dataService.GetAllEmployeesAsync())
                               .FirstOrDefault(u => u.Email.Equals(user.Mail));

                if (employee != null)
                {
                    employee.Arrival   = user.ArrivalTime;
                    employee.Departure = user.DepartureTime;
                    await _dataService.InsertOrUpdateEmployeeAsync(employee);
                }
            }
            catch (Exception ex)
            {
                if (!IsConnected)
                {
                    await _dialogService.ShowAlertAsync("No network connection, please check your internet.", "Service unavailable", "Ok");
                }
                Debug.WriteLine($"[UpdateEmployeeTimeRange] Error updating in: {ex}");
            }
        }
        private async void FetchUser([NotNull] GraphUser user)
        {
            var socId     = "FB." + user.Id; //TODO: move to consts
            var userExist = false;           //await _vm.GetIdIfExist(socId); //TODO: return

            if (userExist)
            {
                Frame.Navigate(typeof(EventsList));//TODO: Use PRISM navigation service
                return;
            }

            var userModel = new UserInfo //TODO: it comes empty
            {
                FirstName           = user.FirstName,
                Surname             = user.LastName,
                Patronymic          = user.MiddleName,
                UserToken           = Session.ActiveSession.CurrentAccessTokenData.AccessToken,
                UserTokenExpiration = Session.ActiveSession.CurrentAccessTokenData.Expires.GetUnixTimeStamp(),
                SocialId            = socId,
                Email = (string)user["email"] //,
                                              //Photo = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", user.Id, "square", Session.ActiveSession.CurrentAccessTokenData.AccessToken) //TODO
            };

            Frame.Navigate(typeof(LoginPageForm), userModel); //TODO: Use PRISM navigation service
        }
Esempio n. 10
0
        public static string getUser(string token, string userPrincipalName)
        {
            string    endPoint           = "https://graph.microsoft.com/v1.0/users/" + userPrincipalName + "?$select=id";
            string    responseFromServer = requestGet(endPoint, token);
            GraphUser graphUser          = JsonConvert.DeserializeObject <GraphUser>(responseFromServer);

            return(graphUser.id);
        }
Esempio n. 11
0
        public async void RetrieveMyInformation()
        {
            _me = await _officeGraphClient.GetMyInformationAsync();

            if (_me != null)
            {
                AnnounceProperty("Me");
            }
        }
        private string BuildUserInfoDisplay(GraphUser user)
        {
            var userInfoname = new StringWriter();

            userInfoname.WriteLine(string.Format("{0}", user.FirstName));
            //userInfoname.WriteLine(string.Format("Name:  {0} {1} {2} {3}", user.FirstName, user.MiddleName, user.LastName, user.ProfilePictureUrl));
            userInfoname.WriteLine();
            return(userInfoname.ToString());
        }
Esempio n. 13
0
        private void AddDriverToList(GraphUser driver, ObservableCollection <GraphUser> drivers)
        {
            driver.Distance = UserHelper.CalculateDistance(App.CurrentUser, driver);

            if (driver.Distance.HasValue && !driver.Distance.Value.Equals(Double.NaN))
            {
                drivers.Add(driver);
            }
        }
        private async Task RetriveUserInfo()
        {
            var client = new FacebookClient(Session.ActiveSession.CurrentAccessTokenData.AccessToken);

            dynamic result = await client.GetTaskAsync("me"); //TODO: me?fields=picture p-o-c

            var currentUser = new GraphUser(result);

            FetchUser(currentUser);
        }
Esempio n. 15
0
 public ADUser(GraphUser user) : this()
 {
     Id          = user.Id;
     DisplayName = user.DisplayName;
     FirstName   = user.GivenName;
     LastName    = user.Surname;
     OfficeRole  = user.JobTitle == null ? "" : user.JobTitle;
     Mail        = user.Mail;
     MobilePhone = user.MobilePhone;
     Office      = user.OfficeLocation == null ? "" : user.OfficeLocation.ToString();
 }
Esempio n. 16
0
            async Task OnTokenValidated(JwtBearer.TokenValidatedContext tokenValidatedContext)
            {
                var passed = false;

                var identity = (ClaimsIdentity)tokenValidatedContext.Principal.Identity;

                // See if there's a UPN, and if so, use that object id
                var upn = identity.Claims.FirstOrDefault(c => c.Type == "upn")?.Value;

                if (upn != null)
                {
                    var oid = identity.Claims.FirstOrDefault(c => c.Type == "oid")?.Value;

                    // get the user
                    var context    = new AuthenticationContext($"{_azureOptions.AADInstance}{_azureOptions.TenantId}", null); // No token caching
                    var credential = new ClientCredential(_azureOptions.ClientId, _azureOptions.ClientSecret);

                    var incomingToken = ((JwtSecurityToken)tokenValidatedContext.SecurityToken).RawData;
                    var result        = await context.AcquireTokenAsync(graphResourceId, credential, new UserAssertion(incomingToken));

                    var       url  = $"{adminOptions.Value.GraphInstance}{_azureOptions.TenantId}/users/{oid}?api-version=1.6";
                    GraphUser user = null;
                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        var resp = await client.GetAsync(url).ConfigureAwait(false);

                        if (resp.IsSuccessStatusCode)
                        {
                            user = JsonConvert.DeserializeObject <GraphUser>(await resp.Content.ReadAsStringAsync().ConfigureAwait(false));
                        }
                    }

                    if (user?.SignServiceConfigured == true)
                    {
                        passed = true;

                        identity.AddClaim(new Claim("keyVaultUrl", user.KeyVaultUrl));
                        identity.AddClaim(new Claim("keyVaultCertificateName", user.KeyVaultCertificateName));
                        identity.AddClaim(new Claim("timestampUrl", user.TimestampUrl));
                        identity.AddClaim(new Claim("access_token", incomingToken));
                    }
                }

                if (!passed)
                {
                    // If we get here, it's an unknown value
                    tokenValidatedContext.Fail("User is not configured");
                }

                telemetryClient.Context.User.AuthenticatedUserId = upn;
            }
Esempio n. 17
0
        /// <summary>
        /// Get current logged in user info
        /// </summary>
        public static void GetCurrentUser(Action <FBUser> callback)
        {
            API("me", HttpMethod.GET, (result) =>
            {
                var data = (IDictionary <string, object>)result.Json;
                var me   = new GraphUser(data);

                if (callback != null)
                {
                    callback(new FBUser(me));
                }
            });
        }
Esempio n. 18
0
        public void AddRemoveAADUserByOIDWithStorageKey()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey");
            GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext
            {
                OriginId   = "27dbfced-5593-4756-98a3-913c39af7612",
                StorageKey = new Guid("9b71f216-4c4f-6b74-a911-efb0fa9c777f")
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOIDWithStorageKey");
            newUser = graphClient.GetUserAsync(userDescriptor).Result;

            //
            // Part 3: remove the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOIDWithStorageKey");
            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOIDWithStorageKey");
            GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result;

            try
            {
                if (membershipState.Active)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }
        public async Task <IEnumerable <GraphUser> > GetMyRidersAsync(GraphUser user)
        {
            var users   = new List <GraphUser>();
            var drivers = await _dataService.GetAllDriversAsync();

            var driver = drivers.FirstOrDefault(d => d.Name.Equals(user.UserPrincipalName));

            if (driver != null)
            {
                if (!string.IsNullOrEmpty(driver.Rider1) && driver.Rider1Status)
                {
                    var graphRider = await _userService.GetUserByDisplayNameAsync(driver.Rider1);

                    if (graphRider != null)
                    {
                        users.Add(new GraphUser(graphRider));
                    }
                }
                if (!string.IsNullOrEmpty(driver.Rider2) && driver.Rider2Status)
                {
                    var graphRider = await _userService.GetUserByDisplayNameAsync(driver.Rider2);

                    if (graphRider != null)
                    {
                        users.Add(new GraphUser(graphRider));
                    }
                }
                if (!string.IsNullOrEmpty(driver.Rider3) && driver.Rider3Status)
                {
                    var graphRider = await _userService.GetUserByDisplayNameAsync(driver.Rider3);

                    if (graphRider != null)
                    {
                        users.Add(new GraphUser(graphRider));
                    }
                }
                if (!string.IsNullOrEmpty(driver.Rider4) && driver.Rider4Status)
                {
                    var graphRider = await _userService.GetUserByDisplayNameAsync(driver.Rider4);

                    if (graphRider != null)
                    {
                        users.Add(new GraphUser(graphRider));
                    }
                }
            }

            return(users);
        }
Esempio n. 20
0
        public void AddRemoveAADUserByUPN()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserAAD");
            GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext
            {
                PrincipalName = "*****@*****.**"
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD");
            newUser = graphClient.GetUserAsync(userDescriptor).Result;

            //
            // Part 3: remove the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserAAD");
            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipStateAAD");
            GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result;

            try
            {
                if (membershipState.Active)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }
Esempio n. 21
0
        public void AddRemoveAADUserByOID()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOID");
            GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext
            {
                OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b"
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetUser-AddRemoveAADUserByOID");
            newUser = graphClient.GetUserAsync(userDescriptor).Result;

            //
            // Part 3: remove the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUser-AddRemoveAADUserByOID");
            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetMembershipState-AddRemoveAADUserByOID");
            GraphMembershipState membershipState = graphClient.GetMembershipStateAsync(userDescriptor).Result;

            try
            {
                if (membershipState.Active)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }
        public void LookupSubject()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOIDWithStorageKey");
            GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext
            {
                OriginId   = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b",
                StorageKey = Guid.NewGuid()
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: add the AAD group
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADGroupByOIDWithStorageKey");
            GraphGroupCreationContext addAADGroupContext = new GraphGroupOriginIdCreationContext
            {
                OriginId   = "f0d20172-7b96-42f6-9436-941433654b48",
                StorageKey = Guid.NewGuid()
            };

            GraphGroup newGroup        = graphClient.CreateGroupAsync(addAADGroupContext).Result;
            string     groupDescriptor = newGroup.Descriptor;

            Context.Log("New group created! ID: {0}", groupDescriptor);


            //
            // Part 3: lookup subjects
            //
            GraphSubjectLookup subjectLookup = new GraphSubjectLookup(new[] {
                new GraphSubjectLookupKey(newGroup.Descriptor),
                new GraphSubjectLookupKey(newUser.Descriptor)
            });

            ClientSampleHttpLogger.SetOperationName(this.Context, "LookupSubjects");
            IReadOnlyDictionary <SubjectDescriptor, GraphSubject> lookups = graphClient.LookupSubjectsAsync(subjectLookup).Result;
        }
Esempio n. 23
0
        private async Task UpdateUserPhotoAsync(GraphUser user)
        {
            try
            {
                var photo = await _userService.GetUserPhotoAsync(user.Mail);

                if (photo != null)
                {
                    user.PhotoStream = ImageSource.FromStream(() => new MemoryStream(photo));
                }
            }
            catch
            {
                user.PhotoStream = null;
            }
        }
        public static double CalculateDistance(GraphUser me, GraphUser user)
        {
            if (me.HasLocation() && user.HasLocation())
            {
                var dist = MapHelper.CalculateDistance(
                    me.Location().Value.Latitude,
                    me.Location().Value.Longitude,
                    user.Location().Value.Latitude,
                    user.Location().Value.Longitude,
                    DistanceMeasure.Miles);

                return(dist);
            }

            return(Double.NaN);
        }
        private ObservableCollection <CustomPin> CalculateDrivePushpins(GraphUser driver)
        {
            ObservableCollection <CustomPin> pins = new ObservableCollection <CustomPin>();

            if (driver.HasLocation())
            {
                pins.Add(driver.CreateUserPin());
            }

            if (driver.HasWorkLocation())
            {
                pins.Add(driver.CreateWorkPin());
            }

            return(pins);
        }
Esempio n. 26
0
        public void AddRemoveAADUserByUPN()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "CreateUserAAD");
            GraphUserCreationContext addAADUserContext = new GraphUserPrincipalNameCreationContext
            {
                PrincipalName = "*****@*****.**"
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "GetUserAAD");
            //newUser = graphClient.GetUserAsync(userDescriptor).Result;  //BUG ???: {"TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\\[email protected]' could not be found."}

            //
            // Part 3: remove the user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "DeleteUserAAD");
            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            try
            {
                ClientSampleHttpLogger.SetOperationName(this.Context, "GetDisabledUserAAD");
                newUser = graphClient.GetUserAsync(userDescriptor).Result;
                if (!newUser.Disabled)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }
        /// <summary>
        /// Get current logged in user info
        /// </summary>
        public static void GetCurrentUser(Action <FBUser> callback)
        {
#if NETFX_CORE
            API("me", HttpMethod.GET, (result) =>
            {
                var data = (IDictionary <string, object>)result.Json;
                var me   = new GraphUser(data);

                if (callback != null)
                {
                    callback(new FBUser(me));
                }
            });
#else
            throw new PlatformNotSupportedException("");
#endif
        }
Esempio n. 28
0
        public void AddRemoveAADUserByOID()
        {
            // Get the client
            VssConnection   connection  = Context.Connection;
            GraphHttpClient graphClient = connection.GetClient <GraphHttpClient>();

            //
            // Part 1: add the AAD user
            //
            ClientSampleHttpLogger.SetOperationName(this.Context, "MaterializeAADUserByOID");
            GraphUserCreationContext addAADUserContext = new GraphUserOriginIdCreationContext
            {
                OriginId = "e97b0e7f-0a61-41ad-860c-748ec5fcb20b"
            };

            GraphUser newUser        = graphClient.CreateUserAsync(addAADUserContext).Result;
            string    userDescriptor = newUser.Descriptor;

            Context.Log("New user added! ID: {0}", userDescriptor);

            //
            // Part 2: get the user
            //
            //newUser = graphClient.GetUserAsync(userDescriptor).Result; //BUG ???: TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' and identifier '45aa3d2d-7442-473d-b4d3-3c670da9dd96\[email protected]' could not be found.

            //
            // Part 3: remove the user
            //

            graphClient.DeleteUserAsync(userDescriptor).SyncResult();

            // Try to get the deleted user
            try
            {
                newUser = graphClient.GetUserAsync(userDescriptor).Result;
                if (!newUser.Disabled)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                Context.Log("The deleted user is not disabled!");
            }
        }
Esempio n. 29
0
        async void CallAuthenticate()

        {
            var x = new CloudData();
            AuthenticationResult token = await x.GetAccessToken();

            System.Diagnostics.Debug.WriteLine("Debug: access token " + token);

            if (token == null)

            {
                await DisplayAlert("Alert", "User has cancelled login or the browser is incompatible", "OK");

                var About = new Views.AboutPage();

                // Navigate to our scanner page
                //await Navigation.PushModalAsync(About);
                //NavigationPage.SetHasBackButton(this, false);

                Application.Current.MainPage = About;

                return;
            }

            GraphUser y = await x.GetDisplayName();

            //await DisplayAlert("Alert", "Welcome, " + y, "OK");

            var displayName = new Item
            {
                Id   = y.displayName,
                Text = "Welcome! You have successfully logged in"
            };

            var Scanner = new Scanner.Scanner();

            Scanner.BindingContext = displayName;

            // Navigate to our scanner page
            //await Navigation.PushModalAsync(Scanner);
            //NavigationPage.SetHasBackButton(this, false);

            Application.Current.MainPage = Scanner;
        }
Esempio n. 30
0
        public async Task <IActionResult> ResetPassword(Guid id, GraphUser model)
        {
            try
            {
                var details = await GetUserDetailsForId(id);

                var pw = await adminService.UpdatePasswordAsync(id);

                ViewBag.Password = pw;


                return(View(nameof(Details), details));
            }
            catch (Exception e)
            {
                ModelState.TryAddModelError("", e.Message);
                return(View(model));
            }
        }
 /// <summary>
 /// Initializes a new instance of the UserInfoChangedEventArgs class.
 /// </summary>
 /// <param name="user">The current user.</param>
 public UserInfoChangedEventArgs(GraphUser user)
 {
     this.User = user;
 }