Do not right-click on your project and select “Add STS Reference...” in an ASP.NET STS project. Doing so will overwrite your STS’s metadata.

In Visual Studio, open the File menu and select New, Web Site. Select ASP.NET Security Token Service Web Site.

If you look at your web.config file, you’ll see a number of differences from the web.config for a typical ASP.NET Web site.

  • The following application settings have been added:

      Copy Code
    	<add key="IssuerName" value="PassiveSigninSTS"/>
    	<add key="SigningCertificateName" value="CN=STSTestCert"/>
    	<add key="EncryptingCertificateName" value=""/>
    The STS uses a default certificate to sign the tokens it issues. This cert is named “STSTestCert” and it is added to your certificate store automatically for use by the STS. The certificate file is present in the STS project. The password for the file is “STSTest”. This should not be used in a production exercise. You can replace the default certificate with any other certificate. Please ensure that the user for your IIS process has access to the private key for any such certificate. You might also choose to create a type derived from IssuerNameRegistry to perform a programmatic validation of certificates of the trusted issuers.

  • All users have been granted access to the federation metadata. The federation metadata contains information about the public key of the token signing certificate, the endpoints that are exposed by the STS, and what claims are issued.

      Copy Code
    <location path="FederationMetadata">
    			<allow users="*" />
  • The <system.Web>/<assemblies> element now contains a reference to the Microsoft.IdentityModel.dll assembly:

      Copy Code
    <add assembly="Microsoft.IdentityModel, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  • Forms authentication and a login page are specified:

      Copy Code
    <authentication mode="Forms">
    	<forms loginUrl="Login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" />
    <!-- Deny Anonymous users. -->
    	<deny users="?" />
  • A trace has been added, which you can uncomment to enable tracing. For more information, see WIF Tracing and How to: Enable Tracing.

      Copy Code
      Uncomment the lines below to enable WIF tracing to: WIFTrace.e2e. 
      Open the trace file using the SvcTraceViewer.exe tool (shipped with the WCF SDK available from Microsoft) or a xml viewer.
      Refer to MSDN if you wish to add WCF tracing.
    	<source name="Microsoft.IdentityModel" switchValue="Verbose">
    		<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="WIFTrace.e2e" />
    	<trace autoflush="true" />

In the App_Code folder, open CustomSecurityTokenService.cs.

  • Update static readonly string[] PassiveRedirectBasedClaimsAwareWebApps to include the URLs of relying party applications to which you want this STS to issue tokens.

  • In the override of the GetOutputClaimsIdentity method, add the claims that your relying party application requires the STS to issue, as well as any custom claims that you want your STS to issue.

CustomSecurityTokenService.cs implements the following required methods.

  1. GetScope. This method takes the caller’s IClaimsPrincipal and the incoming RST and returns the configuration for the token issuance request, which is represented by the Scope class. In this method, you can normalize the relying party’s address and choose signing and encryption keys. Typically, security tokens are encrypted so that only the relying party can read them.

  2. GetOutputClaimsIdentity. This method takes the caller’s IClaimsPrincipal, the incoming RST, and the Scope object returned from GetScope, and returns the IClaimsIdentity to be included in the issued token. This lets you decide which claims are included in the token.