ACSサンプルの1つにカスタムSAMLトークン生成コードがあることを覚えています。それは始めるのに良い場所になるでしょう。 hereをダウンロードし、OAuth2CertificateSample、SelfSignedSaml2TokenGenerator.csを探してください。コードは次のようになります。また
/// <summary>
/// Creates a SAML assertion signed with the given certificate.
/// </summary>
public static Saml2SecurityToken GetSamlAssertionSignedWithCertificate(String nameIdentifierClaim, byte[] certificateWithPrivateKeyRawBytes, string password)
{
string acsUrl = string.Format(CultureInfo.InvariantCulture, "https://{0}.{1}", SamplesConfiguration.ServiceNamespace, SamplesConfiguration.AcsHostUrl);
Saml2Assertion assertion = new Saml2Assertion(new Saml2NameIdentifier(nameIdentifierClaim));
Saml2Conditions conditions = new Saml2Conditions();
conditions.NotBefore = DateTime.UtcNow;
conditions.NotOnOrAfter = DateTime.MaxValue;
conditions.AudienceRestrictions.Add(new Saml2AudienceRestriction(new Uri(acsUrl, UriKind.RelativeOrAbsolute)));
assertion.Conditions = conditions;
Saml2Subject subject = new Saml2Subject();
subject.SubjectConfirmations.Add(new Saml2SubjectConfirmation(Saml2Constants.ConfirmationMethods.Bearer));
subject.NameId = new Saml2NameIdentifier(nameIdentifierClaim);
assertion.Subject = subject;
X509SigningCredentials clientSigningCredentials = new X509SigningCredentials(
new X509Certificate2(certificateWithPrivateKeyRawBytes, password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable));
assertion.SigningCredentials = clientSigningCredentials;
return new Saml2SecurityToken(assertion);
}
、認証プロセスは、フェデレーションメタデータに記述する発行された特許請求の範囲を必要としません。フェデレーションメタデータに公開されたクレームは、発行されたトークンで見つかるべきものについてのトークンコンシューマーにとってのヒントです。
興味深いソリューションをありがとう! –
私が思ったのと同じように、自分のコードで唯一の問題は、署名証明書を設定することを忘れることでした。素晴らしいスニピット。多くの愛。 – Eon
新しいACSダウンロード場所:https://code.msdn.microsoft.com/Windows-Azure-AD-Access-0dcde385 – fiat