Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.

Config for calling an external API

Kristy Overton edited this page Feb 22, 2016 · 4 revisions

It took me a long time to sort this out, so if you're having trouble, maybe it will help. If you want to use ADAL both locally (login/logout) and to authenticate an external API, you'll need a different token for each (if you parse them, you'll see the "audience" change to reflect which thing you're trying to access). You can ensure the tokens get set correctly thusly:

If you've got a website at http://www.mysite.com which wants to access the API at https://whatever.com/myApi...

App.js:

    $locationProvider.html5Mode(true).hashPrefix('!');
    var endpoints = {
        "https://www.whatever.com/myApi": "https://whatever.onmicrosoft.com/MyApi"
    }
    adalProvider.init(
    {
        instance: 'https://login.microsoftonline.com/',
        tenant: 'whatever.onmicrosoft.com',
        clientId: '{clientId of mysite.com}',
        endpoints: endpoints,
        loginResource: '{same as clientId - probably don't NEED this, but it clarifies things}',
        redirectUri: "http://www.mysite.com",
        resource: "https://whatever.onmicrosoft.com/MyApi",
        cacheLocation: 'localStorage' // enable this for IE, as sessionStorage does not work for localhost.`
    },
    $httpProvider`
    );

Clone this wiki locally