public virtual Response UpdateKeyCredentials(string objectId, KeyCredentialsUpdateParameters parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ServicePrincipalsOperations.UpdateKeyCredentials");
     scope.Start();
     try
     {
         return(RestClient.UpdateKeyCredentials(objectId, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
예제 #2
0
        private async Task UpdateADApplication(
            DateTime selfSignedCertStartTime,
            DateTime selfSignedCertEndTime,
            string selfSignedCertString,
            string applicationObjectId)
        {
            var listKeyCredential = new List <KeyCredential>();

            // Query the existing KeyCredentials
            var existingKeyCredentials = await graphClient.Applications.ListKeyCredentialsAsync(applicationObjectId);

            foreach (var existingKeyCredential in existingKeyCredentials)
            {
                // using UTC date as the KeyCredentials dates are in UTC
                var currentDate = DateTime.UtcNow.Date;

                if (existingKeyCredential.EndDate != null)
                {
                    if (existingKeyCredential.EndDate >= currentDate)
                    {
                        listKeyCredential.Add(existingKeyCredential);
                    }
                }
            }

            var keyCredential = new KeyCredential();

            keyCredential.Type      = "AsymmetricX509Cert";
            keyCredential.Usage     = "Verify";
            keyCredential.StartDate = selfSignedCertStartTime;
            keyCredential.EndDate   = selfSignedCertEndTime;
            keyCredential.Value     = selfSignedCertString;

            // Add the new KeyCredential to the list
            listKeyCredential.Add(keyCredential);

            var keyCredentialsUpdateParameters = new KeyCredentialsUpdateParameters(listKeyCredential);

            // Update Application in AD with new cert
            try
            {
                await graphClient.Applications.UpdateKeyCredentialsAsync(
                    applicationObjectId,
                    keyCredentialsUpdateParameters);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
 public virtual async Task <Response> UpdateKeyCredentialsAsync(string applicationObjectId, KeyCredentialsUpdateParameters parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ApplicationsClient.UpdateKeyCredentials");
     scope.Start();
     try
     {
         return(await RestClient.UpdateKeyCredentialsAsync(applicationObjectId, parameters, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
예제 #4
0
 /// <summary>
 /// Update the keyCredentials associated with an application.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='applicationObjectId'>
 /// Application object ID.
 /// </param>
 /// <param name='parameters'>
 /// Parameters to update the keyCredentials of an existing application.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateKeyCredentialsAsync(this IApplicationsOperations operations, string applicationObjectId, KeyCredentialsUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateKeyCredentialsWithHttpMessagesAsync(applicationObjectId, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
예제 #5
0
 /// <summary>
 /// Update the keyCredentials associated with an application.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='applicationObjectId'>
 /// Application object ID.
 /// </param>
 /// <param name='parameters'>
 /// Parameters to update the keyCredentials of an existing application.
 /// </param>
 public static void UpdateKeyCredentials(this IApplicationsOperations operations, string applicationObjectId, KeyCredentialsUpdateParameters parameters)
 {
     operations.UpdateKeyCredentialsAsync(applicationObjectId, parameters).GetAwaiter().GetResult();
 }
예제 #6
0
 /// <summary>
 /// Update the keyCredentials associated with a service principal.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='objectId'>
 /// The object ID for which to get service principal information.
 /// </param>
 /// <param name='parameters'>
 /// Parameters to update the keyCredentials of an existing service principal.
 /// </param>
 public static void UpdateKeyCredentials(this IServicePrincipalsOperations operations, string objectId, KeyCredentialsUpdateParameters parameters)
 {
     operations.UpdateKeyCredentialsAsync(objectId, parameters).GetAwaiter().GetResult();
 }
예제 #7
0
 /// <summary>
 /// Update keyCredentials associated with an existing service principal.
 /// Reference:
 /// https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='objectId'>
 /// Object id to get service principal information.
 /// </param>
 /// <param name='parameters'>
 /// Parameters to update keyCredentials of an existing service principal.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateKeyCredentialsAsync(this IServicePrincipalsOperations operations, string objectId, KeyCredentialsUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     await operations.UpdateKeyCredentialsWithHttpMessagesAsync(objectId, parameters, null, cancellationToken).ConfigureAwait(false);
 }
예제 #8
0
 /// <summary>
 /// Update keyCredentials associated with an existing service principal.
 /// Reference:
 /// https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#keycredential-type
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='objectId'>
 /// Object id to get service principal information.
 /// </param>
 /// <param name='parameters'>
 /// Parameters to update keyCredentials of an existing service principal.
 /// </param>
 public static void UpdateKeyCredentials(this IServicePrincipalsOperations operations, string objectId, KeyCredentialsUpdateParameters parameters)
 {
     Task.Factory.StartNew(s => ((IServicePrincipalsOperations)s).UpdateKeyCredentialsAsync(objectId, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }