title: How do I send a value through AD-B2C using openid-Connect
body: <p>I am currently developing an application using AD-B2C as my identity provider. This is integrated into the solution using their guidelines at <a href="https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-devquickstarts-graph-dotnet" rel="nofollow noreferrer">AD B2C graph</a>, which uses openid-connect (to the best of my understanding at least).</p>
  
  <p>I need to use a form of email activation (outside of their register policy) and as such I need to be able to pass a value from the URL in the email, through the sign-up process at B2C and back to the redirection URL. </p>
  
  <p>I read somewhere that a parameter called "state" can be used for this:</p>
  
  <blockquote>
    <p>State: A value included in the request that will also be returned in the token response. It can be a string of any content that you want. A randomly generated unique value is typically used for preventing cross-site request forgery attacks. The state is also used to encode information about the user's state in the app before the authentication request occurred, such as the page they were on or the policy being executed.</p>
  </blockquote>
  
  <p>I have tried to append a value to the redirection that happens when transferring the user to the B2C, but I don't know how.</p>
  
  <pre><code>if (!Request.IsAuthenticated)
          { // go to login page
              HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties() { RedirectUri = "/" }, Startup.SignUpSignInPolicyId);
          }
  </code></pre>
  
  <p>The policy is stored in the <b>startup.auth.cs</b> file... </p>
  
  <pre><code>// B2C policy identifiers
      public static string SignUpPolicyId = ConfigurationManager.AppSettings["ida:SignUpPolicyId"];
      public static string SignInPolicyId = ConfigurationManager.AppSettings["ida:SignInPolicyId"];
      public static string SignUpSignInPolicyId = ConfigurationManager.AppSettings["ida:SignUpSignInPolicyId"];
      public static string ProfilePolicyId = ConfigurationManager.AppSettings["ida:UserProfilePolicyId"];
      public static string PasswordResetPolicyId = ConfigurationManager.AppSettings["ida:PasswordResetPolicyId"];
  </code></pre>
  
  <p>....and is run during the <b>ConfigureAuth</b> method:</p>
  
  <pre><code>public void ConfigureAuth(IAppBuilder app)
      {
          app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
  
          app.UseCookieAuthentication(new CookieAuthenticationOptions()
          {
              CookieHttpOnly = true,
              ExpireTimeSpan = TimeSpan.FromHours(1),
          });
  
          // Configure OpenID Connect middleware for each policy
          app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignUpPolicyId));
          app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(ProfilePolicyId));
          app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignInPolicyId));
          app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(SignUpSignInPolicyId));
          app.UseOpenIdConnectAuthentication(CreateOptionsFromPolicy(PasswordResetPolicyId));
      }
  </code></pre>
  
  <p>which calls: </p>
  
  <pre><code>private OpenIdConnectAuthenticationOptions CreateOptionsFromPolicy(string policy)
      {
          return new OpenIdConnectAuthenticationOptions
          {
              // For each policy, give OWIN the policy-specific metadata address, and
              // set the authentication type to the id of the policy
              MetadataAddress = String.Format(aadInstance, tenant, policy),
              AuthenticationType = policy,
  
              // These are standard OpenID Connect parameters, with values pulled from web.config
              ClientId = clientId,
              RedirectUri = redirectUri,
              PostLogoutRedirectUri = redirectUri,
              Notifications = new OpenIdConnectAuthenticationNotifications
              {
                  AuthenticationFailed = AuthenticationFailed,
              },
              Scope = "openid",
              ResponseType = "id_token",
              //// This piece is optional - it is used for displaying the user's name in the navigation bar.
              //TokenValidationParameters = new TokenValidationParameters
              //{
              //    NameClaimType = "name",
              //},
          };
  
      }
  </code></pre>
  
  <p>How do I pass a value like: (simplified example:)</p>
  
  <pre><code>if (!Request.IsAuthenticated)
          { // go to login page
              HttpContext.GetOwinContext().Authentication.Challenge(
                    new AuthenticationProperties() { RedirectUri = "/" }, Startup.SignUpSignInPolicyId, new { state = "value=uniquetoken&amp;token=secrets" });
          } 
  </code></pre>
  
  <p>When these methods and policies are set on runtime ? 
  Furthermore if I am heading in a completely wrong direction, where do I go from here?</p>
  
  <p>Any help is appreciated :) </p>
  
  <p>Best Regards</p>