/// <summary>
 /// Creates a service principal in the  directory.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Graph.RBAC.IServicePrincipalOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a service principal.
 /// </param>
 /// <returns>
 /// Server response for service principal information API call
 /// </returns>
 public static ServicePrincipalGetResult Create(this IServicePrincipalOperations operations, ServicePrincipalCreateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IServicePrincipalOperations)s).CreateAsync(parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParameters createParameters)
        {
            ServicePrincipalCreateParameters graphParameters = new ServicePrincipalCreateParameters
            {
                AppId = createParameters.ApplicationId.ToString(),
                AccountEnabled = createParameters.AccountEnabled
            };

            return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
        }
Пример #3
0
        public ServicePrincipal CreateServicePrincipal(string appId)
        {
            var parameters = new ServicePrincipalCreateParameters
            {
                AccountEnabled = true,
                AppId = appId
            };

            return GraphClient.ServicePrincipal.Create(parameters).ServicePrincipal;
        }
        public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParameters createParameters)
        {
            IList<PasswordCredential> passwordCredentials = createParameters.PasswordCredentials != null
                ? createParameters.PasswordCredentials.Select(psCredential => psCredential.ToGraphPasswordCredential()).ToList()
                : null;

            IList<KeyCredential> keyCredentials = createParameters.KeyCredentials != null
                ? createParameters.KeyCredentials.Select(psCredential => psCredential.ToGraphKeyCredential()).ToList()
                : null;

            ServicePrincipalCreateParameters graphParameters = new ServicePrincipalCreateParameters
            {
                AppId = createParameters.ApplicationId.ToString(),
                AccountEnabled = createParameters.AccountEnabled,
                KeyCredentials = keyCredentials,
                PasswordCredentials = passwordCredentials
            };

            try
            {
                return GraphClient.ServicePrincipals.Create(graphParameters).ToPSADServicePrincipal();
            }
            catch (GraphErrorException ce)
            {
                if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
                {
                    AADObject currentUser = GraphClient.Objects.GetCurrentUser();
                    if (currentUser != null && string.Equals(currentUser.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new InvalidOperationException(ProjectResources.CreateServicePrincipalNotAllowedGuestUser);
                    }
                }

                throw;
            }
        }
        private ServicePrincipal CreateNewAdServicePrincipal(ResourcesController controllerAdmin, string appId)
        {
            var spParam = new ServicePrincipalCreateParameters
            {
                AppId = appId,
                AccountEnabled = true
            };

            return controllerAdmin.GraphClient.ServicePrincipal.Create(spParam).ServicePrincipal;
        }
 private static ServicePrincipalGetResult CreateServicePrincipal(ApplicationGetResult app,
     GraphRbacManagementClient graphClient)
 {
     var parameters = new ServicePrincipalCreateParameters
     {
         AccountEnabled = true,
         AppId = app.Application.AppId
     };
     var servicePrincipal = graphClient.ServicePrincipal.Create(parameters);
     return servicePrincipal;
 }
 /// <summary>
 /// Creates a service principal in the  directory.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Graph.RBAC.IServicePrincipalOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters to create a service principal.
 /// </param>
 /// <returns>
 /// Server response for service principal information API call
 /// </returns>
 public static Task<ServicePrincipalGetResult> CreateAsync(this IServicePrincipalOperations operations, ServicePrincipalCreateParameters parameters)
 {
     return operations.CreateAsync(parameters, CancellationToken.None);
 }
        public PSADServicePrincipal CreateServicePrincipal(CreatePSServicePrincipalParameters createParameters)
        {
            ServicePrincipalCreateParameters graphParameters = new ServicePrincipalCreateParameters
            {
                AppId = createParameters.ApplicationId.ToString(),
                AccountEnabled = createParameters.AccountEnabled
            };

            try
            {
                return GraphClient.ServicePrincipal.Create(graphParameters).ServicePrincipal.ToPSADServicePrincipal();
            }
            catch (CloudException ce)
            {
                if (ce.Response.StatusCode == HttpStatusCode.Forbidden)
                {
                    GetCurrentUserResult currentUser = GraphClient.Objects.GetCurrentUser();
                    if (currentUser.AADObject != null && string.Equals(currentUser.AADObject.UserType, "Guest", StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new InvalidOperationException(ProjectResources.CreateServicePrincipalNotAllowedGuestUser);
                    }
                }

                throw;
            }
        }