c# - Web Forms Authentication with B2C -


i'm trying add authentication using azure ad b2c web forms app. unfortunately, every tutorial i've found mvc, except this web forms tutorial. using tutorial, i've added code startup.auth.cs:

public partial class startup {      // more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?linkid=301883     public void configureauth(iappbuilder app)     {         app.setdefaultsigninasauthenticationtype(cookieauthenticationdefaults.authenticationtype);          app.usecookieauthentication(new cookieauthenticationoptions());          app.useopenidconnectauthentication(             new openidconnectauthenticationoptions             {                 clientid = "my-client-id",                 authority = "https://login.microsoftonline.com/my-tenant"             });     } } 

and working fine. however, need have sign functionality sign-in, can't figure out how it, since i've found mvc, , i'm not sure how convert need. i've tried adding code such this:

app.useopenidconnectauthentication(createoptionsfrompolicy(_signuppolicyid)); app.useopenidconnectauthentication(createoptionsfrompolicy(_profilepolicyid)); app.useopenidconnectauthentication(createoptionsfrompolicy(_signinpolicyid)); 

and creates 3 more buttons on login page, clicking on them gives 404 error , no information, don't know how make work, either, or if i'm headed in right direction. i've never worked b2c before, if has suggestions/has done sort of thing web forms, i'd appreciate tips or sample code.

the example using using "local accounts" enter image description here

local accounts mean local database, , each idenity provider add button.

try change authentication "no authentication" (and add files yourself) or "work , school accounts" (which connects ad, convert b2c).

you see redirect https://login.microsoftonline.com/yourtenant.onmicrosoft.com/....

the next steps follow same steps mvc example, implement same pieces of code.

make sure update nuget packages newer version(1.0 , 4.0 default):

<package      id="microsoft.identitymodel.protocol.extensions"     version="1.0.2.206221351"      targetframework="net46" /> <package      id="system.identitymodel.tokens.jwt"      version="4.0.2.206221351"      targetframework="net46" /> 

and code:

    public void configureauth(iappbuilder app)     {         app.setdefaultsigninasauthenticationtype(cookieauthenticationdefaults.authenticationtype);          app.usecookieauthentication(new cookieauthenticationoptions());          app.useopenidconnectauthentication(createoptionsfrompolicy(signinpolicyid));     }   private openidconnectauthenticationoptions createoptionsfrompolicy(string policy)     {          return new openidconnectauthenticationoptions         {             metadataaddress = string.format(aadinstance, tenant, policy),             authenticationtype = policy,              clientid = clientid,             redirecturi = "https://localhost:44300/",             postlogoutredirecturi = redirecturi,             notifications = new openidconnectauthenticationnotifications             {             },              scope = "openid",             responsetype = "id_token",              tokenvalidationparameters = new tokenvalidationparameters             {                 nameclaimtype = "name",             },         };     } 

add /account/signin.aspx page, , in code behind place code mvc sample signin:

 if (!request.isauthenticated)         {                             // execute policy, need trigger owin challenge.             // can indicate policy use adding authenticationproperties using             // policykey provided.             httpcontext.current.getowincontext().authentication.challenge(                 new authenticationproperties()                 {                     redirecturi = "/",                 },                 appconfiguration.b2csigninpolicyid);         } 

Comments