ADAL JS not attaching user token while invoking WebApi
<p>I am using <code>ADAL JS</code> for authenticating the users against Azure AD. And as I am new to <code>ADAL JS</code>, I started reading with following articles, which I find very informative:</p>
<ul>
<li><a href="http://www.cloudidentity.com/blog/2015/02/19/introducing-adal-js-v1/" rel="nofollow noreferrer">Introducing ADAL JS v1</a></li>
<li><a href="http://www.cloudidentity.com/blog/2014/10/28/adal-javascript-and-angularjs-deep-dive/" rel="nofollow noreferrer">ADAL JavaScript and AngularJS – Deep Dive</a></li>
</ul>
<p>After reading the articles, I had the impression that <code>ADAL JS</code> intercepts the service calls and if the service url is registered as one of the endpoint in <code>AuthenticationContext</code> configuration, it attaches the JWT token as Authentication Bearer information.</p>
<p>However, I found the same is not happening in my case. And after some digging, it seemed to me that it is only possible, if <code>adal-angular</code> counter part is also used, which I am not using currently, simply because my web application is not based on Angular.</p>
<p>Please let me know if my understanding is correct or not. If I need to add the bearer information explicitly, the same can be done, but I am more concerned whether I am missing some out-of-the-box facility or not.</p>
<p><strong>Additional Details:</strong> My present configuration looks like following:</p>
<pre><code>private endpoints: any = {
    &quot;https://myhost/api&quot;: &quot;here_goes_client_id&quot;
}
...
private config: any;
private authContext: any = undefined;
....
this.config = {
    tenant: &quot;my_tenant.onmicrosoft.com&quot;,
    clientId: &quot;client_id_of_app_in_tenant_ad&quot;,
    postLogoutRedirectUri: window.location.origin,
    cacheLocation: &quot;sessionStorage&quot;,
    endpoints: this.endpoints
};
this.authContext = new (window[&quot;AuthenticationContext&quot;])(this.config);
</code></pre>
<p>Also on server-side (WebApi), Authentication configuration (Startup.Auth) is as follows:</p>
<pre><code>public void ConfigureOAuth(IAppBuilder app, HttpConfiguration httpConfig)
{
    app.UseWindowsAzureActiveDirectoryBearerAuthentication(
        new WindowsAzureActiveDirectoryBearerAuthenticationOptions
        {
            Tenant = &quot;my_tenant.onmicrosoft.com&quot;,
            TokenValidationParameters = new TokenValidationParameters
            {
                ValidAudience = &quot;client_id_of_app_in_tenant_ad&quot;
            }
         });
}
</code></pre>
<p>However, the <code>Authorization</code> is always null in <code>request.Headers</code>.</p>
<p><strong>UPDATE:</strong> It seems that the same applies for auto-renewal of tokens as well; when used in conjunction with <code>adal-angular</code>, the renewal of token works seamlessly by calling <code>AuthenticationContext.acquireToken(resource, callback)</code> under the hood. Please correct me if I am wrong.</p>