1

I'm integrating Azure AD login authentication to my web app. I have created an account in azure development portal and registered my app details. Following detail are provided during the app registration in azure portal. I have provided my web app's login URL for Sign-on URL

Sign-on URL -> https://my-sample-app/my.dashboard/

Redirect url is ->https://my-sample-app/my.dashboard/azureLogin.html?

Now when I login to portal.office.com and sign in with my credentials , I can see my web apps icon in the office 365 landing page. when I select my web app's icon , I'm getting redirected to my web app's login page instead of redirecting to the redirect URL provided during app registration.

Initially I didn't provide the Sign-on URL but once I tested without providing this I got "undefined Sign-on URL provided for app" error. So I provided my web app's login URL for Sign-on URL field, now I'm getting redirecting to my web app's login page instead of the mentioned redirect URL

I have used ADAL library for acquiring the access token . below is the code.

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://my-sample-app/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;
  }

I'm sure that issue is not with the code. please advise what I'm missing here

Heisenberg
  • 147
  • 1
  • 4
  • 14
  • Is the problem that the button Office portal goes to sign-on URL? Because that's what that property is designed to do. – juunas Sep 25 '19 at 13:35
  • what I expect is : after logging into the portal.office.com and selecting my app button, the code written in the redirect URL path should get invoked and acquire the access tokens , save it in session and redirect to my apps's landing page (this is how I should achieve the single sign-on in my app) What happens now: on clicking the app button in office 365, my app's login URL is loaded where I'm supposed to enter the app's user name & password – Heisenberg Sep 25 '19 at 14:02
  • Typically the sign-on URL is a URL that triggers login against AAD. So if it sends the user to login and specifies the correct redirect_uri, everything should work. I didn't quite understand yet where it goes in the wrong way. – juunas Sep 25 '19 at 14:04

0 Answers0