Azure Graph API - Multiple web platforms redirect URL not working

Waqar Saleemi 0 Reputation points
2024-01-18T19:21:26.7666667+00:00

I am working with Azure Graph API and it works well when I configure only one web platform having one redirect URL. When I add multiple Web platforms and having multiple redirect URLs, it always redirects back to the last/latest redirect URLs. User's image

As I have multiple urls configured, it should work with different applications hosted.

public void Configuration(IAppBuilder app) {
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
            
            var _Configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var RedirectUri = _Configuration.GetSection("AzureAd:RedirectUri").Value;

            app.UseCookieAuthentication(new CookieAuthenticationOptions());
            OwinTokenAcquirerFactory factory = TokenAcquirerFactory.GetDefaultInstance<OwinTokenAcquirerFactory>();
            
            app.AddMicrosoftIdentityWebApp(factory);
            factory.Services
                .Configure<ConfidentialClientApplicationOptions>(options => { options.RedirectUri = RedirectUri; })
                .AddMicrosoftGraph()
                .AddInMemoryTokenCaches();
            factory.Build();
        }
// Sign in


            if (!Request.IsAuthenticated) {
                var context = HttpContext.GetOwinContext();
                context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
                context.Authentication.Challenge(
                    new AuthenticationProperties { RedirectUri = RedirectUri },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,449 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AsithwMSFT 1,420 Reputation points Microsoft Vendor
    2024-01-21T03:58:10.9566667+00:00

    @Waqar Saleemi

    You need to change the redirect URI that you retrieved from appSettings.json.
    var RedirectUri = _Configuration.GetSection("AzureAd:RedirectUri").Value;

    The value of AzureAd:RedirectUri should be changed to the desired redirect URL.

    I Hope this helps. If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.