Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify the webApi endpoint #10

Closed
skypyxis opened this issue Feb 19, 2018 · 2 comments
Closed

How to specify the webApi endpoint #10

skypyxis opened this issue Feb 19, 2018 · 2 comments

Comments

@skypyxis
Copy link

skypyxis commented Feb 19, 2018

On adalConfig.js how can we specify an endpoint different from 'api'? (e.g. 'http://localhost:5000/api/')

If I do this:

export const adalConfig = {
    tenant: '<tenant>',
    clientId: '<clientid>',
    endpoints: {
        'http://localhost:5000/api/': '<webapi_appid>',
    },
   cacheLocation: 'localStorage',
};

I get this error on adalApiFetch:
Uncaught (in promise) {message: "resource is required", msg: "resource is required"}

@salvoravida
Copy link
Owner

salvoravida commented Feb 19, 2018

?!?! i think you are a little bit confused:

endpoints are the GUID of azure Active Directory web app that host your api.

for example if you have 2 api web-endpoint

https://myapi1.azurewebsites.net has a GUID 'XXXXXXX......'
https://myapi2.azurewebsites.net has a GUID 'YYYYYYY......'

Here is adalConfig.js

import { AuthenticationContext, adalFetch } from 'react-adal';

export const adalConfig = {
  tenant: 'AZURE ADAL TENTEN GUID',
  clientId: 'AZURE APP CLIENT ID',
  endpoints: {
    myapi1: 'XXXXXXXXXXXXXXX',
    myapi2: 'YYYYYYYYYYYYYYY',
  },
  cacheLocation: 'localStorage',
};

export const authContext = new AuthenticationContext(adalConfig);

export const adalApi1Fetch = (fetch, url, options) =>
  adalFetch(authContext, adalConfig.endpoints.myapi1, fetch, url, options);

export const adalApi2Fetch = (fetch, url, options) =>
  adalFetch(authContext, adalConfig.endpoints.myapi2, fetch, url, options);

@sealightPT
Copy link

sealightPT commented Feb 20, 2018

Thank you!
I thought "endpoints" was a dictionary (key, value) of (baseUrl, webAppGuid) but it isn't.

Your example of
export const adalApi1Fetch = (fetch, url, options) => adalFetch(authContext, adalConfig.endpoints.myapi1, fetch, url, options);

made it very clear of how it is being used!
Thanks!

@skypyxis skypyxis changed the title How to specify the How to specify the webApi endpoint Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants