react-adal icon indicating copy to clipboard operation
react-adal copied to clipboard

Deep linking to dynamic url

Open ravibha opened this issue 5 years ago • 6 comments

Hi, I have setup authentication for my react app with react-adal. However, if a user directly goes to a page other than what's set in reply urls, I get the following message: AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application.

Is there a way to solve this issue using react-adal? Please note, I cannot add each url of the website to the reply url list, since these can be dynamic. Ex: https://localhost/orders/1, https://localhost/orders/2 etc.

Thanks -Ravi

ravibha avatar Dec 06 '19 04:12 ravibha

how hve you configured reply url?

salvoravida avatar Dec 06 '19 15:12 salvoravida

The reply url is set in the Azure AD app that we use for authentication. I believe we cannot specify wildcards in the reply urls such as https://localhost/*. And I cannot have https://localhost/orders/1, https://localhost/orders/2 etc. there since these are dynamic.

ravibha avatar Dec 06 '19 18:12 ravibha

We're having the same issue, let's call it on Application A, using 0.4.24. Another of our applications, Application B, is using 0.4.18 and does not have this issue. I haven't yet tried downgrading App A to 0.4.18 nor have I tried the latest 0.5.0 release. As far as I can tell, App A & B are configured the same in AAD though A is hosted in AKS and B is hosted in an App Service.

I'll try both 0.4.18 and 0.5.0 in App A to see if either resolves the issue but if there is a known issue with 0.4.24 it would be great to get confirmation.

Abe-Froman avatar Jan 08 '20 17:01 Abe-Froman

Neither downgrading to 0.4.18 nor upgrading to 0.5.0 resolved this issue for me. =(

Abe-Froman avatar Jan 08 '20 17:01 Abe-Froman

I've solved it for our case. The solution was to provide a redirectUri value in adalConfig which points to the root of our application. For example:

export const adalConfig: AdalConfig = {
  tenant: <tenant_id>,
  clientId: <client_id>,
  endpoints: {
    api: <client_id>
  },
  cacheLocation: 'localStorage',
  redirectUri: https://<my_app_root> // <-- added this
}

Abe-Froman avatar Jan 08 '20 18:01 Abe-Froman

Just a little FYI if you used create-react-app you can write your code as follows

import { AuthenticationContext, adalFetch, withAdalLogin } from "react-adal";

let redirecttionURI;
process.env.NODE_ENV === "production"
  ? (redirecttionURI = "https://your-production-site-here/")
  : process.env.NODE_ENV === "test"
  ? (redirecttionURI = "https://your-staging-site-here/")
  : redirecttionURI = "http://localhost:xxxx/";

export const adalConfig = {
  tenant: "xxxxxxxxxxxxxxxxxxxxxxx",
  clientId: "xxxxxxxxxxxxxxxxxxxx",
  endpoints: {
    api: "https://graph.microsoft.com"
  },
  cacheLocation: "localStorage",
  redirectUri: redirecttionURI
};

export const authContext = new AuthenticationContext(adalConfig);

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

export const withAdalLoginApi = withAdalLogin(
  authContext,
  adalConfig.endpoints.api
);

mazer-rakham avatar Mar 05 '20 19:03 mazer-rakham