private static async Task CleanupPermissionGrantsAsync(IActiveDirectoryClient client, OAuthGrant grant)
        {
            IServicePrincipal servicePrincipal = await GetServicePrincipalAsync(client, grant.Application.AppId);

            if (servicePrincipal == null)
            {
                Log(string.Format("No existing service principal for app {0}", grant.Application.DisplayName));
                return;
            }
            Log(string.Format("Deleting existing service principal for app {0}", grant.Application.DisplayName));
            await servicePrincipal.DeleteAsync();
        }
Exemple #2
0
        /// <summary>
        /// To ensure the latest Service Principal with the most up-to-date permissions are created,
        /// if exists, remove the existing Service Principal for YOUR AAD application
        /// </summary>
        /// <param name="client"></param>
        /// <param name="grant"></param>
        /// <returns></returns>
        private static async Task CleanupPermissionGrantsAsync(IActiveDirectoryClient client,
                                                               OAuthGrant grant)
        {
            IServicePrincipal servicePrincipal = await GetServicePrincipalAsync(client, grant.Application.AppId);

            if (servicePrincipal == null)
            {
                Program.WriteInfo($"No existing service principal for app {grant.Application.DisplayName}");
                return;
            }
            Program.WriteInfo($"Deleting existing service principal for app {grant.Application.DisplayName}");
            await servicePrincipal.DeleteAsync();
        }