Search code examples
javaazureazure-active-directoryadaladal4j

Unable to open my app from office 365 portal. getting undefined sign-on url for application error


I'm integrating Azure AD login authentication to my web app. I have created an account in azure development portal and registered my app as web app. In the app registration settings, I have provided the redirect URL like below,

redirect URL: https://mdb-dev-ext.xyzcde.com/my.dashboard/azureLogin.html?

In my java web app, I have implemented the logic to acquire the azure 's token in the above mentioned end point (azureLogin.html). I have used ADAL java library to implement the below code logic

private AuthenticationResult acquireTokenByAuthorizationCode(String authCode) {
    String authority = System.getProperty("dashboard.azure.authority.url", "https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxx/oauth2/token");
    String clientId = System.getProperty("dashboard.azure.client.id", "xxxxxxxxxxxxxxxxxxxxxxxxx");
    String clientSecret = System.getProperty("dashboard.azure.client.secret", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    String redirectUrl = System.getProperty("dashboard.azure.redirect.uri", "https://mdb-dev-ext.xyzcde.com/my.dashboard/azureLogin.html?");
    AuthenticationResult result = null;
    ExecutorService service = null;
    try {
      service = Executors.newFixedThreadPool(1);
      AuthenticationContext context = new AuthenticationContext(authority, false, service);
      ClientCredential credential = new ClientCredential(clientId, clientSecret);
      Future<AuthenticationResult> future = context.acquireTokenByAuthorizationCode(authCode, URI.create(redirectUrl), credential, null);
      result = future.get();
    } catch (Exception e) {
      LOGGER.error("Error occurred while acquiring token from Azure {}", e.getMessage());
      throw new Exception(String.format("Error occurred while acquiring token from Azure. %s", e.getMessage()));
    }
    return result;
  }

Note: i have not provided value for "home page URL" i believe this is not mandatory

Now while doing the following steps I'm facing the error

Login to portal.office.com

sign in with my account credentials

After landing to the office 365 home page , I can see my web app's icon listed

on clicking my web app's icon/button , i'm getting redirected and finally throwing the below error. there are no log updates in my web app's server log. i'm sure that this has not reached my web app.

"You cannot access this application because it has been misconfigured. Contact your IT department and include the following information:
Undefined Sign-On URL for application"

If I provided my web app's login URL for home page URL field like below,

home page URL: https://mdb-dev-ext.xyzcde.com/my.dashboard

then while trying to open the my app from office 365 , it is opening my web app's login page (where it will prompt to enter application's DB username & password). this is not what i'm looking for.

what i want to achieve is -> login to office 365 -> click my web app button -> the redirect URL mentioned in the azure portal during my app registration should load - > which will eventually call the code logic written in my web app to acquire the azure token and login to my app with the azure returned token stored in session.

please let me know what I miss here. why i'm getting this Undefined Sign-On URL for application error ? on click of my app's icon in office 365 portal, why it is not redirecting to the redirect URL configured ?


Solution

  • Issue: "You cannot access this application because it has been misconfigured. Contact your IT department and include the following information: Undefined Sign-On URL for application"

    Regarding the error, you need to configure home page url then you can fix the error. For more details, please refer to https://learn.microsoft.com/en-us/azure/active-directory/develop/registration-config-specific-application-property-how-to#branding. enter image description here

    Issue: on click of my app's icon in office 365 portal, why it is not redirecting to >the redirect URL configured ?

    Regarding the issue, I think you miss something about Sign-On URL and redirect url. Sign-On URL and redirect url are different. Typically the sign-on URL is a URL that triggers login against AAD. The redirect url is the location that the authorization server will send the user to once the app has been successfully authorized.