Language

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 クラスの実装から呼び出されます。

適用対象