コード例 #1
0
        private static IFabricPrincipal CreateUserPrincipal(FabricGraphApiUser userEntry)
        {
            var principal = new FabricPrincipal
            {
                UserPrincipal    = userEntry.User.UserPrincipalName,
                TenantId         = userEntry.TenantId,
                FirstName        = userEntry.User.GivenName ?? userEntry.User.DisplayName,
                LastName         = userEntry.User.Surname,
                MiddleName       = string.Empty, // this value does not exist in the graph api
                IdentityProvider = IdentityProviders.AzureActiveDirectory,
                PrincipalType    = PrincipalType.User,
                SubjectId        = userEntry.User.Id,
                IdentityProviderUserPrincipalName = userEntry.User.UserPrincipalName
            };

            principal.DisplayName = $"{principal.FirstName} {principal.LastName}";
            return(principal);
        }
        public AzureDirectoryProviderServiceUserTests()
        {
            _mockGraphClient = new Mock <IMicrosoftGraphApi>();
            _allUsers        = new ActiveDirectoryDataHelper().GetMicrosoftGraphUsers();
            _firstUser       = _allUsers.First();
            _emptyUsers      = new List <FabricGraphApiUser>();
            _oneUserResult   = new List <FabricGraphApiUser>()
            {
                _firstUser
            };

            _mockGraphClient.Setup(p => p.GetUserCollectionsAsync(It.IsAny <string>(), null))
            .Returns(Task.FromResult(_emptyUsers));
            var filterWildSetting  = String.Format(_userFilterWildQuery, this._firstUser.User.DisplayName, _firstUser.User.Surname, this._firstUser.User.GivenName);
            var filterExactSetting = String.Format(_userFilterExactQuery, _firstUser.User.DisplayName);

            _mockGraphClient.Setup(p => p.GetUserCollectionsAsync(filterWildSetting, null))
            .Returns(Task.FromResult(_oneUserResult));

            _mockGraphClient.Setup(p => p.GetUserCollectionsAsync(filterExactSetting, null))
            .Returns(() =>
            {
                var userEntry =
                    _allUsers.FirstOrDefault(p =>
                                             AzureSearchEqualsPredicate(p, _directorySearchForJason));

                if (userEntry == null)
                {
                    return(null);
                }

                List <FabricGraphApiUser> user = new List <FabricGraphApiUser>();
                user.Add(userEntry);
                return(Task.FromResult((IEnumerable <FabricGraphApiUser>)user));
            });

            _mockGraphClient.Setup(p => p.GetUserAsync(_firstUser.User.Id, null))
            .Returns(Task.FromResult(_firstUser));

            _mockLogger      = new Mock <ILogger>();
            _providerService = new AzureDirectoryProviderService(_mockGraphClient.Object, _mockLogger.Object);
        }
        private async Task <FabricGraphApiUser> GetUserByTenantAsync(string subjectId, string tenantId)
        {
            var token = await _azureActiveDirectoryClientCredentialsService.GetAzureAccessTokenAsync(tenantId);

            if (token != null)
            {
                var client  = GetNewClient(token);
                var apiUser = await client.Users[subjectId].Request().GetAsync().ConfigureAwait(false);
                if (apiUser != null)
                {
                    FabricGraphApiUser user = new FabricGraphApiUser(apiUser)
                    {
                        TenantId = tenantId
                    };
                    return(user);
                }
            }

            return(null);
        }
コード例 #4
0
        private static FabricPrincipal CreateUserPrincipal(FabricGraphApiUser userEntry)
        {
            var principal = new FabricPrincipal
            {
                UserPrincipal    = userEntry.User.UserPrincipalName,
                TenantId         = userEntry.TenantId,
                TenantAlias      = userEntry.TenantAlias ?? userEntry.TenantId,
                FirstName        = userEntry.User.GivenName ?? userEntry.User.DisplayName,
                LastName         = userEntry.User.Surname,
                MiddleName       = string.Empty, // this value does not exist in the graph api
                IdentityProvider = FabricIdentityConstants.SearchIdentityProviders.AzureActiveDirectory,
                PrincipalType    = FabricIdentityEnums.PrincipalType.User,
                SubjectId        = userEntry.User.Id,
                IdentityProviderUserPrincipalName = string.IsNullOrEmpty(userEntry.User.Mail)
                    ? userEntry.User.UserPrincipalName
                    : userEntry.User.Mail
            };

            principal.Email       = principal.IdentityProviderUserPrincipalName;
            principal.DisplayName = $"{principal.FirstName} {principal.LastName}";
            return(principal);
        }
コード例 #5
0
        public static Mock <IMicrosoftGraphApi> SetupAzureDirectoryGraphUser(this Mock <IMicrosoftGraphApi> mockAdGraphUser, FabricGraphApiUser principal)
        {
            mockAdGraphUser.Setup(p => p.GetUserAsync(directorySearchForJamesRocket, null))
            .Returns((string subjectId, string tenantId) => Task.FromResult(principal));


            mockAdGraphUser.Setup(p => p.GetUserAsync(directorySearchForJamesRocket, "1"))
            .Returns((string subjectId, string tenantId) => Task.FromResult(principal));
            return(mockAdGraphUser);
        }