I've got an existing ASP.NET web app which is non-MVC and I would like to get it to call the Microsoft graph. I read up on the ASPNET MVC tutorials and got those to work but I am looking for some code samples of calling the Microsoft Graph that don't use MVC or OWIN to acquire an access token. This is because I would like to avoid rewriting my entire app into MVC. Any pointers?
Microsoft has a number of samples on Github. Here's a console app one.
Related
I need to implement Azure AD authentication and authorization for my ASP.NET MVC web application using MSAL.NET with authorization code flow and I need to call my own API.
I can see a lot of manual code implementations on the internet to redeem authorization codes etc...
I know the latest version of MSAL.NET will handle auto code redeem without writing any manual code but how to use it, any good example will help me a lot.
Second, what are the best practices followed while using MSAL.NET with authorization code flow to call my own API?
Note: I am using the .net framework.
Thanks in advance.
This might be helpful
Microsoft.Identity.Web adds extension methods that provide convenience services for calling Microsoft Graph or a downstream web API. These methods are explained in detail in A web app that calls web APIs: Call an API. With these helper methods, you don't need to manually acquire a token.
https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-acquire-token?tabs=aspnetcore
https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
Also you can use custom solution like below
https://identitymodel.readthedocs.io/en/latest/client/token.html
Start reading from here, it supports the following frameworks:
.Net Core
.Net framework
For MVC ensure first that u are using either Asp.net Core or normal .net framework. Once you have figured that out. You can find the relevant code which you can refer to generate the token logic.
Read here for more details about the MSAL authentication library.
MSAL authentication library for dot net
Code samples collection.
https://learn.microsoft.com/en-us/azure/active-directory/develop/sample-v2-code
I have developed an ASP.Net MVC application which is Azure Single-Sign-On supported.
In the existing application, I wanted to consume online SharePoint REST API's to work with the document library(Get folders/files,upload, add, replace and delete etc.)
Is there any way to do/achieve this task.
Thanks in advance!
yes, the supported way is to use SharePoint CSOM which is now in .net standard. Please see this article were you may find a movie that shows the whole process to add nuget, authenticate the app and get some data from SharePoint, and here is he msdn support.
Some CSOM examples how this works
I am going to create an web app using Dot Net Core. In future, i will also create mobile application for the same application. Now, i am in thinking the architecture of the project. I want to use WEB API core using Asp.net Identity Core. Also, i will consume WEB API in MVC Core application. But the question i have in mind that how i can handle ASP.net identity with MVC and WEB API? Do i need to include in MVC as well or only in WEB API?
I tried to think hard but still confuse. Need suggestions.
You can use token based authentication .
In a resource owner flow scenario , your client app( mvc application/native application) will consume your web api by providing user's credential , web api will validate the credential(using ASP.NET Core Identity) in database , If the username and password are correct then a JWT authentication token and the user details are returned. Your client app could validate the token and sign in user :
ASP.NET Core 2.2 - JWT Authentication Tutorial with Example API
Tutorial built with
Token Authentication in ASP.NET Core 2.0 - A Complete Guide
In addition, IdentityServer4 is a good choice when you want to roll your own full-fledged OpenID Connect authorization server that can handle complex use cases like federation and single sign-on.
So your question is maybe a bit open-ended for Stackoverflow and you don't really show what you have tried so far.
I will try to answer though. First you just need to start out with a template for your project. Start an MVC project in which you can easily have API endpoints as well. I would suggest splitting those in two projects for clarity - but if it is just a small personal project then you probably are fine having them in the same project. Microsoft have a pretty good resource on MVC:
Microsoft MVC walkthrough
For the Identity part. You would need some kind of authority for it to work. I suggest you take a look at IdentityServer4. Which offers an excellent walk-through of how to set it up and how to integrate it with Asp.NET Core Identity:
IdentityServer4
I developed a website in ASP.NET MVC 4 using NHibernate, now I need to perform an integration with the site using Windows Forms.
How can I perform authentication system using the same users?
What technology should I use? Web API, SOAP or Rest?
Thanks!
Small clarification of terms : REST is an architectural style, SOAP is a protocol for exchanging information, and Web API is a framework to build HTTP Services.
The stock answer for questions like this is "It depends"
Before you continue with a technology selection, currently is your method for authenticating users separated properly from your business/presentation logic?
If that is the case, being that you are using MVC 4, Web API may be the path of least resistance, you can put all of the functionality that requires authentication behind Web API calls. And your controllers will call them. Once that is done, a Windows forms app can consume the data in a similar way.
I saw that ASP.Net MVC4 WebApi exposes services as a Rest ones.
But what is actually the difference between normal Rest and ASP.Net MVC4 WebApi?
I'm not sure what you mean by normal Rest.
REST is a paradigm.
HTTP is a protocol that follows that paradigm.
ASP.NET Web API allows developers to write ASP.NET applications that can be accessed via HTTP and adhere to the REST paradigm. While you could create a REST API without Web API, Web API provides a ton of features that will remove a lot of the pain associated with creating a truly RESTful API in ASP.NET.
apigee has many great resources for REST API best practicies.
Are you asking about the general REST standard or the way that REST has been done traditionally on the Microsoft platform prior to the MVC4 Web API? I am thinking you are approaching this as the second one.
The updated approach in MVC4 gives you more REST capabilities without the WCF model. Here is a recent post on the subject: http://mattmilner.com/Milner/Blog/post/2012/02/28/WebAPI-or-WCF.aspx.