.Net Core Office365 Auth Correlation failed RRS feed

  • Question

  • I doing some testing on .net project which requires Office365 authentication. 

    Just started a new web application and added "Work Or School Accounts" authentication, inserted my domain and "Read directory data" enabled. 

    Allowed visual studio to generate code, I can see it generated a new app under my azure portal and everything seems to be ok.

    Try to run the project, and when login in with office365 I get the folllwing error.

    Exception: Correlation failed.

    Unknown location

    Exception: An error was encountered while handling the remote login.


    Exception: An error was encountered while handling the remote login.

    • Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()

    • Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

    • Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)

    • Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

    I can't understand why this is happening, can someone please help? 

    My Startup.cs file looks like this.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Authentication;
    using Microsoft.AspNetCore.Authentication.AzureAD.UI;
    using Microsoft.AspNetCore.Authentication.OpenIdConnect;
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Authorization;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.IdentityModel.Tokens;
    namespace VumaPortal
        public class Startup
            public Startup(IConfiguration configuration)
                Configuration = configuration;
            public IConfiguration Configuration { get; }
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
                services.Configure<CookiePolicyOptions>(options =>
                    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                    options.CheckConsentNeeded = context => true;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                    .AddAzureAD(options => Configuration.Bind("AzureAd", options));
                services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
                    options.TokenValidationParameters = new TokenValidationParameters
                        // Instead of using the default validation (validating against a single issuer value, as we do in
                        // line of business apps), we inject our own multitenant validation logic
                        ValidateIssuer = false,
                        // If the app is meant to be accessed by entire organizations, add your issuer validation logic here.
                        //IssuerValidator = (issuer, securityToken, validationParameters) => {
                        //    if (myIssuerValidationLogic(issuer)) return issuer;
                    options.Events = new OpenIdConnectEvents
                        OnTicketReceived = context =>
                            // If your authentication logic is based on users then add your logic here
                            return Task.CompletedTask;
                        OnAuthenticationFailed = context =>
                            context.HandleResponse(); // Suppress the exception
                            return Task.CompletedTask;
                        // If your application needs to do authenticate single users, add your user validation below.
                        //OnTokenValidated = context =>
                        //    return myUserValidationLogic(context.Ticket.Principal);
                services.AddMvc(options =>
                    var policy = new AuthorizationPolicyBuilder()
                    options.Filters.Add(new AuthorizeFilter(policy));
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
                if (env.IsDevelopment())
                app.UseMvc(routes =>
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");


    Friday, February 14, 2020 12:11 PM


  • Hello,

    For ASP.NET related question use

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    • Marked as answer by AndrePereira58 Friday, February 14, 2020 1:43 PM
    Friday, February 14, 2020 1:35 PM