Επεξεργασία

Κοινή χρήση μέσω


SecurityTokenServiceConfiguration.CreateSecurityTokenService Method

Definition

Creates an security token service (STS) instance from the Type specified in the SecurityTokenService property.

public:
 virtual System::IdentityModel::SecurityTokenService ^ CreateSecurityTokenService();
public virtual System.IdentityModel.SecurityTokenService CreateSecurityTokenService ();
abstract member CreateSecurityTokenService : unit -> System.IdentityModel.SecurityTokenService
override this.CreateSecurityTokenService : unit -> System.IdentityModel.SecurityTokenService
Public Overridable Function CreateSecurityTokenService () As SecurityTokenService

Returns

An instance of the Type specified in the SecurityTokenService property.

Examples

The code examples that are used in the SecurityTokenService topics are taken from the Custom Token sample. This sample provides custom classes that enable processing of Simple Web Tokens (SWT) and it includes an implementation of a passive STS that is capable of serving an SWT token. For an example of how to implement an active STS, you can see the Federation Metadata sample. For information about these samples and other samples available for WIF and about where to download them, see WIF Code Sample Index. The following code shows a custom implementation of the SecurityTokenServiceConfiguration class to support a passive STS that processes SWT tokens. The configuration is initialized and stored in the HTTP application state the first time the static Current property is accessed. The constructor initializes the properties of the custom configuration with the type of the custom STS, a custom issuer token resolver, and the default token type (the URI of the SWT token type). It also adds an SWT token handler to the default handler collection.

The following code shows how to invoke a custom passive STS to process a WS-Federation request by calling the FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(HttpRequest, ClaimsPrincipal, SecurityTokenService, HttpResponse) method from the code behind in the default.aspx.cs file. The CreateSecurityTokenService method initializes an instance of the PassiveSTS.CustomSecurityTokenService class using the properties set on the current CustomSecurityTokenServiceConfiguration object. The CustomSecurityTokenServiceConfiguration.Current property is implemented by the CustomSecurityTokenServiceConfiguration class and returns the instance of the class that is saved in the HTTP application state.

using System;
using System.IdentityModel.Services;
using System.Security.Claims;

namespace PassiveSTS
{
    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// We perform the WS-Federation Passive Protocol processing in this method. 
        /// </summary>
        protected void Page_PreRender( object sender, EventArgs e ) 
        {
            FederatedPassiveSecurityTokenServiceOperations.ProcessRequest( Request, User as ClaimsPrincipal, CustomSecurityTokenServiceConfiguration.Current.CreateSecurityTokenService(), Response );
        }
    }
}

Remarks

The class specified in the SecurityTokenService property must implement a constructor that takes a parameter of type SecurityTokenServiceConfiguration.

Applies to