SecurityTokenHandler.CreateToken(SecurityTokenDescriptor) メソッド

定義

派生クラスでオーバーライドされると、指定されたトークン記述子を使用してセキュリティ トークンを作成します。 このメソッドは、セキュリティ トークン サービス (STS) によって呼び出されます。

public:
 virtual System::IdentityModel::Tokens::SecurityToken ^ CreateToken(System::IdentityModel::Tokens::SecurityTokenDescriptor ^ tokenDescriptor);
public virtual System.IdentityModel.Tokens.SecurityToken CreateToken (System.IdentityModel.Tokens.SecurityTokenDescriptor tokenDescriptor);
abstract member CreateToken : System.IdentityModel.Tokens.SecurityTokenDescriptor -> System.IdentityModel.Tokens.SecurityToken
override this.CreateToken : System.IdentityModel.Tokens.SecurityTokenDescriptor -> System.IdentityModel.Tokens.SecurityToken
Public Overridable Function CreateToken (tokenDescriptor As SecurityTokenDescriptor) As SecurityToken

パラメーター

tokenDescriptor
SecurityTokenDescriptor

サブジェクトの作成元のセキュリティ トークン記述子。 トークン記述子のプロパティは、このメソッドを呼び出す前に設定されます。

戻り値

トークン記述子のプロパティと一致するセキュリティ トークン。

次のコードは、 メソッドをオーバーライド CreateToken してトークン記述子からトークンを作成して返す方法を示しています。 コードはサンプルから取得されます Custom Token 。 このサンプルでは、Simple Web Tokens (SWT) の処理を可能にするカスタム クラスを提供します。 WIF で使用できるこのサンプルとその他のサンプルの詳細と、それらをダウンロードする場所については、「 WIF コード サンプル インデックス」を参照してください。

public override SecurityToken CreateToken(SecurityTokenDescriptor tokenDescriptor)
{
    if (tokenDescriptor == null)
    {
        throw new ArgumentNullException("tokenDescriptor");
    }

    NameValueCollection properties = new NameValueCollection();
    properties.Add(SimpleWebTokenConstants.Id, Guid.NewGuid().ToString());
    properties.Add(SimpleWebTokenConstants.Issuer, tokenDescriptor.TokenIssuerName);
    properties.Add(SimpleWebTokenConstants.Audience, tokenDescriptor.AppliesToAddress);
    properties.Add(SimpleWebTokenConstants.ExpiresOn, SecondsFromSwtBaseTime(tokenDescriptor.Lifetime.Expires));
    properties.Add(SimpleWebTokenConstants.ValidFrom, SecondsFromSwtBaseTime(tokenDescriptor.Lifetime.Created));

    foreach (Claim claim in tokenDescriptor.Subject.Claims)
    {
        properties.Add(claim.Type, claim.Value);
    }

    SimpleWebToken token = new SimpleWebToken(properties);
    return token;
}

注釈

既定では、このメソッドは例外を NotImplementedException スローします。

クラスの実装から呼び出されます SecurityTokenService

適用対象