Base solution for your next web application
Open Closed

WSFederation Value Can Not Be Null Trying to Register. #2439


User avatar
0
bbakermmc created

If I turn of WSFederation the registration page will work. This error is occurring when it I press "Register" but its not making it to the action in the controller.

[ArgumentNullException: Value cannot be null.
Parameter name: parameter]
   Microsoft.IdentityModel.Protocols.AuthenticationProtocolMessage.SetParameter(String parameter, String value) +103
   Microsoft.IdentityModel.Protocols.WsFederationMessage..ctor(IEnumerable`1 parameters) +217
   Microsoft.Owin.Security.WsFederation.<AuthenticateCoreAsync>d__1f.MoveNext() +1589
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +92
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +58
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +28
public void Configuration(IAppBuilder app)
        {
            app.UseAbp();

            app.UseOAuthBearerAuthentication(AccountController.OAuthBearerOptions);

            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            if (IsTrue("ExternalAuth.Facebook.IsEnabled"))
            {
                app.UseFacebookAuthentication(CreateFacebookAuthOptions());
            }

            if (IsTrue("ExternalAuth.Twitter.IsEnabled"))
            {
                app.UseTwitterAuthentication(CreateTwitterAuthOptions());
            }

            if (IsTrue("ExternalAuth.Google.IsEnabled"))
            {
                app.UseGoogleAuthentication(CreateGoogleAuthOptions());
            }

            if (IsTrue("ExternalAuth.MMCFederation.IsEnabled"))
            {
                app.UseWsFederationAuthentication(CreateWsFederationAuthOptions());
            }

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });

            app.MapSignalR();

            //ENABLE TO USE HANGFIRE dashboard (Requires enabling Hangfire in PlatformWebModule)
            //app.UseHangfireDashboard("/hangfire", new DashboardOptions
            //{
            //    Authorization = new[] { new AbpHangfireAuthorizationFilter() } //You can remove this line to disable authorization
            //});
        }

        private static WsFederationAuthenticationOptions CreateWsFederationAuthOptions()
        {
            var websiteAddress = ConfigurationManager.AppSettings["MMCFederation.Address"];

            var wtrealm = ConfigurationManager.AppSettings["MMCFederation.Address"];
            var metaDataAddress = "https://fs.mmcweb.com/FederationMetadata/2007-06/FederationMetadata.xml";

            return new WsFederationAuthenticationOptions
            {
                Wtrealm = wtrealm,
                MetadataAddress = metaDataAddress,
                AuthenticationType = "Windows",
                Notifications = new WsFederationAuthenticationNotifications
                {
                    RedirectToIdentityProvider = notification =>
                    {
                        if (notification.ProtocolMessage.IsSignOutMessage)
                        {
                            notification.HandleResponse();
                        }

                        notification.ProtocolMessage.Wreply = websiteAddress.EnsureEndsWith('/') + "Account/ExternalLoginCallback";

                        return Task.FromResult(0);
                    },
                    SecurityTokenValidated = notification =>
                    {
                        var name = notification.AuthenticationTicket.Identity.Name;
                        notification.AuthenticationTicket.Identity.AddClaim(new Claim(ClaimTypes.Name, name));
                        return Task.FromResult(0);
                    }
                }
            };
        }

2 Answer(s)
  • User Avatar
    0
    bbakermmc created

    I fixed this by setting my Wreply

    Wreply = websiteAddress.EnsureEndsWith('/') + "Account/ExternalLoginCallback",

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @BBakerMMC :)