active-directory-dotnet-webapp-webapi-openidconnect | NET 4.5 MVC web app that signs Azure AD users | OAuth library
kandi X-RAY | active-directory-dotnet-webapp-webapi-openidconnect Summary
kandi X-RAY | active-directory-dotnet-webapp-webapi-openidconnect Summary
A .NET 4.5 MVC web app that signs Azure AD users in with OpenID Connect and calls a web api using OAuth 2.0 access tokens.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of active-directory-dotnet-webapp-webapi-openidconnect
active-directory-dotnet-webapp-webapi-openidconnect Key Features
active-directory-dotnet-webapp-webapi-openidconnect Examples and Code Snippets
Community Discussions
Trending Discussions on active-directory-dotnet-webapp-webapi-openidconnect
QUESTION
I know this question has been answered, but I don't understand what people exactly do (about certificates, ssl) and they all use a localhost but not me.
I used this sample as my example OpenIdConnect
I'm using:
- A web app
- A web API
Both are using .Net Core 2.1. The Web App is using the Azure AD connection to get a JwtBearer token, that is sent to the API.
Seeing the route /api/information
in the API, a request is sent from the Web App to the API, and the API is returning the error above.
The exact error is:
...ANSWER
Answered 2018-Jun-07 at 14:44Solved it by replacing, in appsettings.json
:
QUESTION
As shown by many samples I have two AAD application registrations, one for my javascript-based front end, and one for my JSON-only web APIs.
If I fully trust my client AAD application, why does AAD require me to create a second AAD application for my web APIs?
For example, assuming I add specific roles to my client AAD application, if client signs in with AAD and gets an id token and access token containing my roles, it only needs to send the access token to my APIs. The API only needs to crack the JWT, validate the audience, issuer, tenant, roles permissions, and signature. In this world, no client secret is needed in the web APIs, a second AAD application registration not needed, and still no call to AAD from my APIs. Unfortunately, without two AAD applications, I cannot figure out a way to have AAD include roles into my access token.
If I didn't fully trust the issuer from mucking with claims, I can see why I would need two AAD applications and a client secret. But since I do trust my AAD application and the signature of the JWT, why the extra complexity? Or maybe there is a way to do this that I haven't found?
Thanks!
Responding to Marc here because just not enough characters in the comments field -- The sample you referenced is an excellent sample, specifically the JavaScript one calling the Web API. It is what I am doing right now in fact. However, the problem is that Web API in the sample is open to anybody who has authenticated on the tenant. I need to secure the Web API down to certain individuals in the tenant, and simply checking the client/app id is not sufficient as anybody who can create an AAD app can fake it.
So what I need to do is have roles added to the the access token so I know that my application authenticated the user, and that user has been granted the required roles. For example, here is a Microsoft sample. And even here a Microsoft video walking through the process.
If I don't have two AAD applications w/client secret, the roles claims is never provided in the access token. It is always provided in the id token, but not the access token.
I feel like I am missing something obvious here. If AAD would just put the roles I requested into the JWT when I authenticated against it, and I validated its signature, audience, issuer, and roles, I wouldn't need any of this extra complexity?
...ANSWER
Answered 2019-Oct-25 at 20:14Can you provide a link showing that two apps are needed? That should only be the case if the API you want to call is not provided by the web app which served the JS to the browser. None of the 'official' samples require you to register two apps (Graph API, used in some of these samples is a separate API and it is already registered). A problem with tokens passed from the browser is that they were acquired by a public client, not using any secrets apart from user creds. Therefore, they are easier to steal and re-use. Your own back-end app may want to use a secret to get its own token (extension grant) to call yet another API using a token that does not reside in a public client.
QUESTION
OpenIdConnect (Azure) Settings
...ANSWER
Answered 2019-May-23 at 06:26What is causing this? I mean, obviously the reverse proxy, but how do I fix it without removing the reverse proxy?
As far as I know, if you use url rewirte rule in the web.config, it will rewrite all the request to the https://my.domain.com/ domain which is include the login.microsoftonline.com.
I suggest you could write a new rule which is used to match the /oauth2 request url to directly rediret to the login.microsoftonline.com instead of the https://my.domain.com/. Then it will work well.
More details, you could refer to below url rewrite rule.
QUESTION
I have hosted one web api ProductInfo
on azure and register that application into Azure AD.
I have another web app UIProduct
and this web app want to access the web api ProductInfo
both are in same Domain and same Azure AD.
How can I access web api ProductInfo
from web app UIProduct
?
is there any token I need to generate again ?
any sample code will be helpful. code sample taken from this link
After successfully login i'm at Home page then i click on about page where i write this
...ANSWER
Answered 2018-Oct-09 at 19:13You'll want to go register both apps in the Azure portal both as Web Apps/APIs.
Then in your Web API, set a App ID URI
as well as create any scopes you'd like to expose. If this is the only client you'll be using, you may be able to just have an Access
scope, but bear in mind this is what end users will see when consenting to your app.
In your web app, you'll then be able to set a Required Permissions
for this new web API and scope. This indicates that the client should require consent for this web API and can be granted access tokens for it.
This code sample covers this exact scenario.
The web API basics doc also covers some conceptual info related to this scenario
QUESTION
I'm currently confused about how to realize the authentication / authorization flow.
I'm developing two applications, the one is the frontend/Webapplication and the other the backend/API, both with ASP.NET Core. The goal is to use the AzureAD and use the users/groups from the domain. The authentication I already implemented on both applications and I'm able to login and restrict content based on the login state.
As reference I took this example from a microsoft developer. There should be exactly this what I want to do. There is a WebApp and API. The used authentication flow is the authorization code flow. First the user needs to login and after that when some data needs to be requested from the API, an access token will be requested.
Question 1: Is this the right authentication flow? For me this seems like a doubled authentication, because first I authenticate myself at the frontend and when the Webapp needs some data I need to authenticate myself again at the backend. The same Azure AD tenant is used, so what do you think here?
The next point what seems very "ugly" is the procedure getting some data. In the example when some data is requested first the token will be requested and after this the data. But in my opinion with a lot of boilerplate. The example code below is needed for just one request of all ToDo items.
...ANSWER
Answered 2018-Aug-10 at 04:59I found a proper solution to solve this.
I just used the approach from this example here multitenant-saas-guidance and it works like charm.
QUESTION
My MVC WebApp is deployed to Azure Paas and secured using Azure AD. The authentication setup uses the sample code below as its base and it is working in localhost with either IISExpress or IIS.
https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect
But it is not working after deployment to Azure. Even though the user will authenticate properly, the AuthorizationCodeReceived delegate is never invoked.
This is start up code that setup the authentication:
...ANSWER
Answered 2017-Jun-13 at 07:01According to reply url : https://albatrossweb.azurewebsites.net/.auth/login/aad/callback/ , it seems you enabled "Authentication / Authorization" feature of azure app service. and i could reproduce that if i enabled "Authentication / Authorization" feature , in that scenario easy authentication will take over the authentication process . If you enabled "Authentication / Authorization" of app service , please try to disable that and try again .
QUESTION
EDIT 10/24 I think this was all likely user error - see my answer below for remedy before getting too deep into this question
TL;DR: For my OAuth 2.0 code flow...
Why does my
TokenCredentials
not work with my AutoRest client? I'm getting NO bearer token applied to the request / no Authorization header set
I know my pipeline works already..
Using code from this azure sample, which is NOT an AutoRest client, I can successfully get my access_token
and can get JSON from my protected Web API project.. so I've ruled out all the prerequisite stuff.. I know my pipeline works
My AutoRest setup..
1.) Downloaded from GitHub this AutoRest repo v1.1.0
2.) Downloaded my swagger JSON to disk, saved as swagger.json
3.) Ran this command-line to generate C# files:
autorest --input-file=swagger.json --csharp --output-folder=MyCorp_ApiClient_Tsl --namespace='MyCorp.ApiClient' --add-credentials
4.) Copied generated classes into my .NET 4.6.2 web site
5.) These are my NuGets:
...ANSWER
Answered 2017-Jul-17 at 13:22While I believe I ran my autorest
command with --add-credentials
it's possible I may have used the older syntax... --AddCredentials true
I also did not run autorest --reset
as the docs recommend you do
One of these is the culprit, because now my 1.1.0 autorest installation is generating everything correctly.
QUESTION
I am testing a webproject using OWIN and OpenID Connect against Azure AD. I am using much of the code from this sample: https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect
I have an issue where i get a null exception on line 27 of this file: https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect/blob/master/TodoListWebApp/Utils/NaiveSessionCache.cs
I get the exception because HttpContext.Current is null.
I can see that Load() is called from BeforeAccessNotification().
My framework version is 4.5.2 and i have in my web.config.
Why is HttpContext.Current null in this context?
Updated:
The only difference i have from the sample is that my ActionResult on my controller is not async. I call AcquireTokenSilentAsync in a async Task that is called with a .Wait() from a standard ActionResult. I am working within a CMS that does not allow me to use async ActionResults.
This is OnAuthorizationCodeReceived:
...ANSWER
Answered 2017-May-16 at 20:58I'm not sure if it's your case, but sometimes the root cause of HttpContext.Current null is a missing key in web.config:
QUESTION
I'm able to authenticate with live.com with my account on outlook.com at url
...ANSWER
Answered 2017-May-28 at 18:52It seems like the retrieving of data with EWS Managed API is not supported with outlook.com accounts.
you can read (in the yellow section) about it here and also here.
Basically, there are 2 portals today that apps can be created with:
It states that for these reasons outlook.com accounts are not supported:
New app registrations should be created and managed in the new Application Registration Portal to be compatible with Outlook.com. This means that if you have an app that was created thru Azure Management Portal it will not be supported with outlook.com and the token will not work with outlook.com accounts.
Existing app registrations that were created in the the Azure Management Portal will continue to work for Office 365 only
Also if you created your app with Application Registration Portal The REST API is currently enabled on all Office 365 accounts that have Exchange Online and only some Outlook.com accounts. this means it is not guaranteed to all outlook.com accounts because they haven't migrated all of them (yet).
Microsoft accounts with Outlook.com mailboxes (including Outlook.com, Hotmail.com, Live.com, MSN.com, and Passport.com) are in the process of being upgraded to enable the REST APIs. During this process, making API calls to mailboxes that are not yet upgraded will return a MailboxNotEnabledForRESTAPI or MailboxNotSupportedForRESTAPI error code.
QUESTION
Question: What could be causing HttpContext.Current
to be null only sometimes?
Question: Is HttpContext.Current
initialized after PrincipalService.OnAzureAuthenticationSuccess
is called? If so, why only sometiems?
Description
What happens is quite often a user will click sign-in and HttpContext.Current
will be null causing the cookie to be never set. Which redirects them back to the home-page and since the cookie wasn't set they click sign-in again and again and again. Sometimes it'll decide to let the cookie be set after 2 or 3 clicks other times it won't do it without clearing cookies or logging out of another Azure AD account (e.g. Our sharepoint server uses Azure AD).
These things seem so odd to me and I haven't been able to pin down what the cause is despite hours of research into it.
Azure Config
...ANSWER
Answered 2017-May-02 at 18:07Alright, so it turns out I was being a big dummy and doing things the hard way. I don't 100% fully understand why it was null but I did find a much simpler way around the issue.
- Started by removing the code related to me creating my own cookie (i.e.
AuthorizationCodeReceived = PrincipalService.OnAzureAuthenticationSuccess
).
What happened was I realized that Azure AD was creating its own principal and cookie via the app.UseCookieAuthentication(new CookieAuthenticationOptions());
This realization happened thanks to the git hub project that Fei Xue linked.
- After that I switched my custom principal to create based on the 'built-in' cookie instead of the cookie I was creating (which was only getting created half of the time due to
HttpContext.Current
beingnull
).
Now that the custom principal creation wasn't dependent on HttpContext.Current
I didn't have a sign-in loop happening at all because the principal and cookie both exist.
Thanks a ton to Fei Xue!
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install active-directory-dotnet-webapp-webapi-openidconnect
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page