Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

How to use Azure AD token in getJson

$
0
0

I have a question regarding passing the authorization token to a web api.  I seem to have it working fine with code based on the sample code (WebApp-WebApi-OpenIdConnect-DotNet).  All my claims show up in the webapi I can make decisions on what to do based on that.  The login uses Azure AD credentials.

I would like to do learn how to do the same with ajax and getJSON.  I am just learning these so I may be way off base.

There are 2 (at least) things I am not sure about:
 - 1:  How to get access to the bearer token in the script
 - 2:  How to pass it along when calling getJSON (assuming that is where it needs to be passed)

For 2 I have a guess (roughly):
 $.getJSON(uri).setRequestHeader('Authorization', 'Bearer' + ' ' + token)

That is based on the sample code doing this:
    request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
That could be off base but it is what I think I will try.


For 1 it is less clear.  I have a webapp like the sample code mentioned above but am trying to use ajax in the view.  Would I pass the token in the viewbag?  Is there some other way that is much better?

Any place that you can point me to or fill in answers would be most appreciated.







Rig Lee


Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>