I wish to upgrade a console application that uses Azure.ResourceManager to report information about subscriptions and resources in an arbitrary Azure subscription. The console application uses the InteractiveBrowserCredentials to pop up a browser window where users can log in (or, most usually, select the applicable Microsoft account they have previously signed into). The application now requires a more interactive front-end, and porting it to Blazor WASM appeared simple; however, at runtime, the following minimal code fails in Blazor WASM:
var armClient = new ArmClient(new InteractiveBrowserCredential());
var subs = armClient.GetSubscriptions().ToArray();
It throws an exception because Monitors can not await on the WASM runtime. InteractiveBrowserCredential authentication failed: Cannot wait on monitors on this runtime.
It is not feasible to add an App Registration to the Azure AD in advance to make this work due to the generic utility nature of the tool; the user should interactively authenticate during the running of the utility.
The console application (and applications like Visual Studio Code) prompts for the necessary credentials at runtime.
What is the best way to replicate the InteractiveBrowserCredential flow from a standalone WASM application?
Related
I need advice as i am new in .net and azure, i am creating a architecture for a project which has its mobile application, web based admin panel and Website.
I am planning to host every thing in Azure. I am creating application in Xamarin. Application needs to have Push Notification, Offline Sync etc, features provided by Mobile App Services (Controller inherited from TableController).
I want to create 1 database which will be used by all 3 modules. I have already created a Mobile App Service and Database. Mobile application is using it as it was supposed to. Now i want to create a website and Web based admin panel and use the same database. Is this possible ?
What is the best way? Should i create a web project and perform operations on data via REST API? and use this API for Mobile Apps and Web based Backend?
I am really confused between different services from azure and which one to use. Should i use .Net Core or .Net. I need to know the best way to do it.
Edit 1 :
So far this is what i have done and i need to know if this will work fine in future when project get complex. I created database and back end via Azure Mobile App. Now i have created a .net MVC website and used RestSharp for CRUD operations in it. I have used the following code to perform the operations. Note the /tables/ part in the request url.
var client = new RestClient("http://xxxxxxx.azurewebsites.net");
var request = new RestRequest("/tables/request?ZUMO-API-VERSION=2.0.0", Method.POST);
string data = "{\"createdFor\":\"535862cf-e2b3-41de-99f9-88c47a77750c\",\"status\":\"IN_PROCESS\",\"createdBy\":\"7108147e-c11c-4d78-ac3d-d5d6c5eb78d0\",\"description\":\"Master room 5 door produces strange sound when opened or closed\",\"title\":\"Door Sounds Strange\"}";
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("application/json", data, ParameterType.RequestBody);
var result = client.Execute(request);
Console.WriteLine("Content " + result.Content);
Get and post operations works fine. Is this a good way?
Thanks in advance
As the official document mentions about Mobile App Features:
Authentication and Authorization (AAD,Facebook, Google, Twitter and Microsoft Account,Custom authentication)
Data Store (SQL Database, Azure Table Storage,etc)
Offline Sync
Push Notifications (Client SDKS seamlessly integrate with the registration capabilities of Azure Notification Hubs)
Client SDKs (A complete set of Client SDKs that cover native development, cross-platform development,etc)
Per my understanding, if the build-in features provided by mobile app could totally meet your requirement, then Mobile App is better for you and it would save your time. For Web API application, you need to do all stuff by yourself.
Now i want to create a website and Web based admin panel and use the same database. Is this possible ?
I assumed that you could create a Azure Mobile App application (Mobile App) and a web application (Azure Web App) under your solution, and you could extract the DbContext related classes into a shared class library.
Should i use .Net Core or .Net. I need to know the best way to do it.
For choosing between .NET Core and .NET Framework, you could refer to the official document about choosing-core-framework-server.
UPDATE:
Can you please take a look at edit 1, and suggest if this is the right way or it can create a problem.
Your code would work fine, since the mobile client SDK just wraps the common processing as your provided.
Note:
For accessing only by authenticated user, you need to add x-zumo-auth header with the authenticationToken after you logged.
Additionally, for your MVC application to retrieve the data from your mobile app (need authentication), you need to log with your mobile app and retrieve the authenticationToken for your subsequent requests against your mobile app. At this point, except for Custom authentication, otherwise you could only leverage Client-managed authentication and use JavaScript client library for Azure Mobile Apps in your MVC application for logging to mobile app and retrieve the authenticationToken, then you could send request from your front-end or pass the token to your back-end. For SPA, you could use both Client-managed authentication and Server-managed authentication.
Moreover, Adrian hall has wrote some useful tutorials about developing against azure mobile app, you could refer to Adrian hall's book.
UPDATE2:
For custom authentication using an Identity Database, you just pass the username and password to your mobile app, then it would validate the user info and generate the authenticationToken. While for Auth0, you firstly login with Auth0 provider, then pass the token to your mobile app.
My mobile application has its own signing up and sign in option with username and password.
For the connection Username-Password-Authentication from Auth0, it would manage the users for you, while using an Identity Database, the users would be stored in your storage and you need to manage them by yourself.
Per my understanding, both approaches could implement the custom authentication for you, but you need to choose the better one that matches your scenario.
I have a Push-Notification service set up that I had to migrate (because IBM is closing the old service).
I used the original app and just opened a new Push-Service.
Now, when I try to test the installation with the REST-API online, it tells me that the app secret isn't valid.
Do I have to open a new app as well? (besides, I can't find the app-secret in the new interface)
What happens to the old mobile apps. Does the service run side by side for a while?
The app-secret value for the new push service is the VCAP credential, not an overall application secret like it was with the old services. The new services are more decoupled and thus only push requires the secret value at this time (added to prevent malicious usage of the REST API) and it is located in a different spot than in the old services.
Here are the steps to grab the app secret from your new push service instance (taken from: https://console.ng.bluemix.net/docs/services/mobilepush/t_restapi.html). Note where it says to click Show Credentials this is in reference to the new push service instance tile on your application dashboard's Connections tab.
With that said I highly recommend migrating completely from your app using the old services (Push, Mobile Data, Mobile Application Security) to a new app using nothing but the new services (Push Notifications, Cloudant NoSQLDB, Mobile Client Access). The services are not intended to work together cross-generation, and should be taken wholesale.
I have c# console application which is using for some long running task. In my local system I am executing it from ASP.Net MVC 5 controller by System.Diagnostics.Process class. Now we are going it to implement it into azure as our site is deployed in azure in development mode.
I am new to azure so don't how to do it.However study several article I have found that I can upload my console application as web jobs. I can run web jobs as trigger i.e. ondemand.
But now my question is how can execute this web job from MVC controller as I need to pass some argument from controller?
Currently there is no direct link between WebSite and WebJob, even though they are executed in the same application pool. And the best way would be to post a message to a queue from you MVC app. And on the other end have your WebJob to check for the queue for new messages. Just like Andres already said.
This will not be instant, but easy to implement and cheap.
If you need instant reaction from your console app, you'll need to implement your background tasks as Worker Roles and deploy as a separate VMs, and have there some sort of network communication going on, so you can always reach out for your worker role via TCP.
You can set up your web site to push an item to an Azure Queue, and then have your web job be triggered every time an item is pushed to the queue.
There is some information, including code samples for how to do that on http://www.asp.net/aspnet/overview/developing-apps-with-windows-azure/getting-started-with-windows-azure-webjobs.
We have this Pub/Sub system that you subscribe to via a callback mechanism in C# to recieve events from various things that happen within the database. This subscription has a callback signature attached to it that allows for the Pub / Sub system to callback any subscribers it has and notify them of the change on that Callback thread.
We are taking our windows application and migrating it into a web application. In doing so, I need a way to update this Web Application (The clients) with information from this Pub / Sub. I want to use SignalR, but not sure where to host it. I assume if I host it on the same Web Application as the Client, it won't be able to subscribe to the pubsub due to it not being able to do background threading.
Currently, I have it in a Console application hosting the SignalR server on a specific port. Obviously this is for testing and not ideal for a larger scale.
My question is.. is it really safe to be hosting SignalR outside of IIS? should I put this in a Windows Service? Web Service somehow? Can it go in a Web Application somehow?
I'll try to make a long story short:
I want to call a method on a hub in a web application from a core assembly in my application. Reason being is that I have a number of applications that all eventually call into core and trigger events (think mobile web, admin site, api, etc). I want to notify users of the desktop site of events as they happen, using SignalR.
To spike this, I created a 4-project solution. A core project with the hub proxy. A web app with the hub. Another web app without the hub. And finally a console app.
If I call into core from the console app, and try to send a message to hub clients using the proxy, everything works great. However, if I try to call into core and use the proxy from one of the web apps, the execution hangs at the call to connection.Start():
var connection = new HubConnection("...");
var hub = connection.CreateProxy("Spike.Hub");
connection.Start().Wait();
Is the SignalR.Client stuff not meant to be used from within a web app's app domain? Why does it work as expected in the console app, but not from a web app?
Update: I hooked my spike into the SignalR source and when running from one of the web apps, execution hangs at line 130 of SignalR.Client.Connection. The _syncContext for such a connection is an instance of AspNetSynchronizationContext, and when calling its Post() method, everything stops.
There's a bug in the SignalR.Client and you found it :)