I want to initiate an Azure-PIM using c#/.net
I already found a PowerShell-Function to do this:
New-AzurePIMRequest ... inside the "PIMTools"-packages: https://www.powershellgallery.com/packages/PIMTools/0.4.0.0
This is working just fine and of course I could just execute a PS-Script containing this from within my C#-Application. But I would prefer to natively achieving the same using a NuGet-Package or a library from within my application.
Is there a package that allows me to achieve the same from within C#?
Those PIMTools are just wrapping some existing powershell modules.You can check the details here: https://github.com/janegilring/PIMTools/blob/main/functions/New-AzurePIMRequest.ps1
As you can see they mainly use the AzureADPreview module which is giving access to the Microsoft Graph Endpoint. Microsoft Graph is a RESTful web API that enables you to access Microsoft Cloud service resources.
You can find the Graph SDK here: https://github.com/microsoftgraph/msgraph-sdk-dotnet
With the SDK installed you can use something like this to issue a PIM Request:
var graphClient = new GraphServiceClient(new DefaultAzureCredential());
var privilegedRoleAssignmentRequest = new PrivilegedRoleAssignmentRequestObject
{
Duration = "2",
Reason = "DevWork",
AssignmentState = "Active",
RoleId = "b24988ac-6180-42a0-ab88-20f7382dd24c",
};
await graphClient.PrivilegedRoleAssignmentRequests
.Request()
.AddAsync(privilegedRoleAssignmentRequest);
Note: You might have to the use the /beta Endpoint of the SDK to get PIM working. However, APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported.
Related
Using the guide here https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-teams-interop?pivots=platform-windows
I am able to join a team meeting from my client app.
Now trying to start a 1:1 call with a teams identity on the client, to another teams identity (on teams); I've tried to use the StartCallAsync method (instead of JoinAsync) from https://learn.microsoft.com/en-us/azure/communication-services/quickstarts/voice-video-calling/get-started-with-voice-video-calling-custom-teams-client
This example is in node - I'm using C# and it looks like the most recent beta build of the SDK does NOT have the threadId property exposed.
Here is the JS code
call_ = await call_agent.startCall([{ microsoftTeamsUserId: calleeTeamsUserId.value.trim() }], { videoOptions: videoOptions, threadId: teamsThreadId });
and this link https://learn.microsoft.com/en-us/javascript/api/azure-communication-services/#azure/communication-calling/startcalloptions?view=azure-communication-services-js states that a threaded is required; however, no such threadId exists for c# SDK
The client goes from a connecting state to a disconnected state - the call never rings
Specific code to make the call
StartCallOptions startCallOptions = new StartCallOptions();
ICommunicationIdentifier[] callees = new ICommunicationIdentifier[1]
{
new MicrosoftTeamsUserIdentifier(*****)
};
call_ = await call_agent.StartCallAsync(callees, startCallOptions);
Azure Communication Services have multiple types of Teams interop, which are in different phases of development by today (1/31/2022). Your combination of interop and programming language is currently not supported. Interop scenarios:
Ability of ACS users to join Teams meeting is generally available for all JS, .net, iOS, Android.
Ability of Teams user manage Teams VoIP calls, Teams PSTN calls, and Teams meetings via ACS JavaScript calling SDK is in public preview. Android, iOS, and .net calling SDKs do not support Teams identities.
You can learn more about the support in the following documentation:
https://learn.microsoft.com/en-us/azure/communication-services/concepts/interop/teams-user-calling
I'm trying to scale programmatically an Azure worker role and I can't find the right syntax for the resource name.
// Create the autoscale client.
AutoscaleClient autoscaleClient = new AutoscaleClient(new CertificateCloudCredentials(subscriptionId, cert));
AutoscaleSettingGetResponse get =autoscaleClient.Settings.Get(AutoscaleResourceIdBuilder.BuildCloudServiceResourceId("WRK-GROUP-NE01","CIW.GROUPS",true) );
AutoscaleSetting setting = get.Setting;
It returns : ResourceNotFound: The resource service name monitoring is not supported.
Can you point me to the right syntax?
The guide which you're following is based on the Azure Service Management model, aka Classic mode, which is deprecated and only exists mainly for backward compatibility support.
You should use the latest Microsoft.Azure.Insights nuget package for getting the autoscale settings.
Sample code using the nuget above is as below:
using Microsoft.Azure.Management.Insights;
using Microsoft.Rest;
//... Get necessary values for the required parameters
var client = new InsightsManagementClient(new TokenCredentials(token));
client.AutoscaleSettings.Get(resourceGroupName, autoScaleSettingName);
See the REST API Reference below for getting the autoscale settings.
GET
https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/microsoft.insights/autoscaleSettings/{autoscale-setting-name}?api-version={api-version}
For updating Autosale setting you can use below api
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/autoscalesettings/{autoscaleSettingName}?api-version=2015-04-01
https://learn.microsoft.com/en-us/rest/api/monitor/autoscalesettings/createorupdate
Hope it helps.
My scenario: Website hosted on the cloud, where each instance creates a subscription to a Service Bus Topic for itself to listen for messages.
My question: How do I programmatically create subscriptions?
Microsoft.Azure.ServiceBus.3.1.0 allows to create a ManagementClient using the ConnectionString.
private async Task CreateTopicSubscriptions()
{
var client = new ManagementClient(ServiceBusConnectionString);
for (int i = 0; i < Subscriptions.Length; i++)
{
if (!await client.SubscriptionExistsAsync(TopicName, Subscriptions[i]))
{
await client.CreateSubscriptionAsync(new SubscriptionDescription(TopicName, Subscriptions[i]));
}
}
}
Original plan for the new Azure Service Bus client was not to include management plane at all and use Azure Active Directory route instead. This has proven to be too problematic, just like you've pointed out. Microsoft messaging team has put together a sample to demonstrate the basic operations.
Note that there's a pending PR to get it working with .NET Core 2.0
Moving forward, it was recognized that developers prefer to access Service Bass using a connection string like they used to over Azure Active Directory option. Management Operations issue is raised to track requests. Current plan is to provide a light weight management library for the .NET Standard client.
For now, the options are either to leverage the old client to create entities or use Microsoft.Azure.Management.ServiceBus (or Fluent) until the management package is available.
Update
Management operations were released as part of 3.1.0 version of the client.
Microsoft.Azure.ServiceBus has been deprecated. The new option is Azure.Messaging.ServiceBus and ManagementClient has been replaced by ServiceBusAdministrationClient.
string connectionString = "<connection_string>";
ServiceBusAdministrationClient client = new ServiceBusAdministrationClient(connectionString);
This new package also supports ManagedIdentity:
string fullyQualifiedNamespace = "yournamespace.servicebus.windows.net";
ServiceBusAdministrationClient client = new ServiceBusAdministrationClient(fullyQualifiedNamespace, new DefaultAzureCredential());
A little example:
var queueExists = await _administrationClient.QueueExistsAsync(queueName);
if(!queueExists)
await _administrationClient.CreateQueueAsync(queueName);
More info here.
I've seen some examples of how to create storage resources using ARM and C#. I'm assuming that the same is possible for apps. However, I can't find a working example.
Ideally I'd like to have a c#/Web api app that would be able to deploy another app. The process should be fully automated.
Basically, I'd like to create a new instance of the same app with its own configuration - the process would be triggered by a new customer signing up for my SaaS.
Could someone please give some pointers on how to deal with the above?
Thanks.
It seems that you’d like to deploy web application (deployment package) to Azure app service web app programmatically in C# code, you can try to use Kudu Zip API that allows expanding zip files into folders. And the following sample code works fine for me, you can refer to it.
//get username and password from publish profile on Azure portal
var username = "xxxxx";
var password = "xxxxxxxxxxxxxxxxxxxx";
var AppName = "{your_app_name}";
var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
var file = File.ReadAllBytes(#"C:\Users\xxx\xxx\WebApplication1.zip");
MemoryStream stream = new MemoryStream(file);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Basic " + base64Auth);
var baseUrl = new Uri($"https://{AppName}.scm.azurewebsites.net/");
var requestURl = baseUrl + "api/zip/site/wwwroot";
var httpContent = new StreamContent(stream);
var response = client.PutAsync(requestURl, httpContent).Result;
}
Besides, you can use Microsoft.Azure.Management.Fluent to manage your Azure app service.
You could grab the Azure Management Libraries for .Net from Github. Support for Azure App Service is in preview as of v1.2. This enables a very intuitive syntax.
var webApp = azure.WebApps.Define(appName)
.WithRegion(Region.USWest)
.WithNewResourceGroup(rgName)
.WithNewFreeAppServicePlan()
.Create();
There are lots of code samples for both Windows and Linux flavours of Azure App Service shown here: https://github.com/Azure/azure-sdk-for-net/tree/Fluent
There are also some worthwhile reading materials on how to handle data in this kind of scenario; various possibilities and design patterns are covered at https://learn.microsoft.com/en-us/azure/sql-database/sql-database-design-patterns-multi-tenancy-saas-applications
I want to integrate my xamarin android app with google play services leaderboards and achievements. I am not getting how to convert below code from android documentation to c#.
// Create the Google Api Client with access to the Play Game and Drive services.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER) // Drive API
.build();
// ...
I tried to convert something like below
GoogleApiClient api = new GoogleApiClient.Builder(this)
.AddApi(Android.Gms.Games.API)
.Build();
It's giving error under "Android.Gms.Games.API"
None of the things mentioned in this stack overflow thread are working. Looks like most of these things deprecated.
Please suggest if any other easy way available to integrate with leaderboards.
EDIT: Made changes and now giving below error.
You will be able to get access to GoogleClientAPI via:
var googleClientAPI = new GoogleApiClient.Builder(Application.Context).AddApi(XXX).Build();
Example using a blocking connect as a quick test:
var client = new GoogleApiClient.Builder(Application.Context)
.AddApi(GamesClass.API)
.AddScope(GamesClass.ScopeGames)
.Build();
Task.Run(() => {
client.BlockingConnect();
System.Diagnostics.Debug.WriteLine(client.IsConnected);
});
Note: This assumes that you have registered your app, otherwise you will get a fatal developer error... see Play Connecting
Since you are needing access to leaderboard and achievements, make sure that you have added the packages:
Xamarin.GooglePlayServices.Games
Xamarin.GooglePlayServices.Identity
These will auto-include the .Base and .Basement package
Namespaces to look at after adding the packages:
using Android.Gms.Common.Apis;
using Android.Gms.Games.LeaderBoard;
using Android.Gms.Games.Achievement;