c# - How do I set AuthenticationScheme and AutomaticAuthenticate in .NET Core 2? -


i tried follow guide allow login of user when running tests in .net core 2

http://geeklearning.io/how-to-deal-with-identity-when-testing-an-asp-net-core-application/

it says should configure authentication middleware test purposes this:

public class testauthenticationoptions : authenticationoptions   {     public virtual claimsidentity identity { get; } = new claimsidentity(new claim[]     {         new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", guid.newguid().tostring()),         new claim("http://schemas.microsoft.com/identity/claims/tenantid", "test"),         new claim("http://schemas.microsoft.com/identity/claims/objectidentifier", guid.newguid().tostring()),         new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", "test"),         new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", "test"),         new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", "test"),     }, "test");      public testauthenticationoptions()     {         this.authenticationscheme = "testauthenticationmiddleware";         this.automaticauthenticate = true;     } } 

this not work since authenticationoptions class have had authenticationscheme , automaticauthenticate properties removed authenticationoptions instance in .net core 2 cf. https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#setting-default-authentication-schemes

so don't know how login in tests work in .net core 2.

you can't way anymore. authenticationscheme can set in startup.cs. branching did not possible more. instead of test-scheme, should use scheme used in application.

public class testauthenticationoptions : authenticationoptions   { public virtual claimsidentity identity { get; } = new claimsidentity(new claim[] {     new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", guid.newguid().tostring()),     new claim("http://schemas.microsoft.com/identity/claims/tenantid", "test"),     new claim("http://schemas.microsoft.com/identity/claims/objectidentifier", guid.newguid().tostring()),     new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", "test"),     new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", "test"),     new claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", "test"), }, "<productionscheme>");      public testauthenticationoptions     {          //nothing here.     } } 

in startup have hopefully:

services.addauthentication("<productionscheme>"); 

maybe can you:

https://github.com/aspnet/announcements/issues/262


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -