The process described in this post was tested on 01/13/2013 using Katana 2.0.2, Visual Studio 2013 and .NET Framework 4.5.
The authentication and authorization space is riddled with acronyms and cryptic terms like realm, issuer, tenant, audience URI and when you combine this with OAuth terminology and implementation specific terms, it becomes even more confusing and it is pretty easy to make mistakes especially if you are handling multiple identity providers.
There are good chances that you may mess up the configuration either in WAAD (Windows Azure Active Directory) or in the application server code. It exactly happened to me while working on a multi-tenant auth handling components for WebAPI; I was running into an authorization error which I had no idea why it’s happening.
I wasn’t sure how to enable tracing on Katana to see if it even helps. So, I resorted to the brute force approach of source code level debugging and thought that this process will save some time if you ever run into this issue.
Here is the process:
Step 1: git clone https://git01.codeplex.com/katanaproject
Step 2: Open “katana.sln” and add your existing ASP.NET WebAPI project to Katana solution.
Step 3: Install Owin using “install-package Owin” from nuget package manager
Step 4: Add references to the following projects in the solution:
[Note: our WebAPI project targets netfx 4.5]
Step 5: Add Startup.cs with the following code:
public partial class Startup
public void ConfigureAuth(IAppBuilder app)
Step 6: Set up break points in OAuthBearerAuthenticationHandler.cs which is located in the project Microsoft.Owin.Security.Oauth.
After all this effort, my problem was caused by a configuration mismatch for the “Audience” URI. App ID URI in the WAAD tenant is equivalent to “ActiveDirectoryFederationServicesBearerAuthenticationOptions.Audience” used by the above configured app.UseActiveDirectoryFederationServicesBearerAuthentication() extension method.
I hope this saves you some time in setting up your debugging environment in troubleshooting authentication issues.