I have a test webforms app downloaded from MS to connect to Azure Ad. It works running in Visual Studio with localhost and IIS express. But when I move it to the server it fails to connect. I have tried multiple things in the authority (tenant id, company) It gets the below stack trace.
[TaskCanceledException: A task was canceled.] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +14354825 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.IdentityModel.Protocols.d__8.MoveNext() +501
[IOException: IDX20804: Unable to retrieve document from: 'https://login.microsoftonline.com/Mytenantid/v2.0/.well-known/openid-configuration'.] Microsoft.IdentityModel.Protocols.d__8.MoveNext() +1372 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.IdentityModel.Protocols.OpenIdConnect.d__3.MoveNext() +379 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.IdentityModel.Protocols.d__24.MoveNext() +848
[InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://login.microsoftonline.com/Mytenantid/v2.0/.well-known/openid-configuration'.] Microsoft.IdentityModel.Protocols.d__24.MoveNext() +1562 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Security.OpenIdConnect.d__8.MoveNext() +547 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Security.Infrastructure.d__40.MoveNext() +349 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31
I have an older version of connecting in the same IIS instance with older packages that works.
URI https://Myserver/TestNewAccess
// Authority is the URL for authority, composed by Microsoft identity platform endpoint and the tenant name (e.g. https://login.microsoftonline.com/contoso.onmicrosoft.com/v2.0)
string authority = String.Format(System.Globalization.CultureInfo.InvariantCulture, System.Configuration.ConfigurationManager.AppSettings["ida:AADInstance"], domain);
public void ConfigureAuth(IAppBuilder app)
{
IdentityModelEventSource.ShowPII = true;
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
//PostLogoutRedirectUri = postLogoutRedirectUri,
RedirectUri = redirectUri,
Scope = OpenIdConnectScope.OpenId,
// ResponseType is set to request the code id_token - which contains basic information about the signed-in user
ResponseType = OpenIdConnectResponseType.CodeIdToken,
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "preferred_username",
ValidateIssuer = true // Simplification (see note below)
},
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = (context) =>
{
return System.Threading.Tasks.Task.FromResult(0);
}
}
}
);
Portion of the web.config.
<location path="Account">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<customErrors mode="Off"/>
<authorization>
<deny users="?" />
</authorization>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<pages>
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>