Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to custom saml attributes #800

Open
AcTeemo opened this issue Nov 5, 2024 · 2 comments
Open

how to custom saml attributes #800

AcTeemo opened this issue Nov 5, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@AcTeemo
Copy link

AcTeemo commented Nov 5, 2024

Hello! I need to add the red attributes shown in the image to the SAML response. How can I do that? plz give me some help. THX!!!!!

image

@simpleidserver
Copy link
Owner

Hello,

I have made some modifications to the Release503 branch to support your requirement.

Could you please follow these steps?

  1. Create a new class CustomSaml2AuthResponseEnricher and copy the following content:
public class CustomSaml2AuthResponseEnricher : ISaml2AuthResponseEnricher
{
    public void Enrich(Saml2SecurityToken securityToken)
    {
        var statements = securityToken.Assertion.Statements;
        foreach (var statement in statements)
        {
            if (statement is Saml2AttributeStatement attributeStatement)
            {
                var userNameAttr = attributeStatement.Attributes.SingleOrDefault(a => a.FriendlyName == "username");
                if(userNameAttr != null)
                {
                    userNameAttr.Name = ClaimTypes.Upn;
                    userNameAttr.NameFormat = new Uri(Saml2MetadataConstants.AttributeNameFormat);
                }
            }
        }
    }
}
  1. Edit the Program.cs file and register the new dependency:
services.AddTransient<ISaml2AuthResponseEnricher, CustomSaml2AuthResponseEnricher>();

@simpleidserver simpleidserver self-assigned this Nov 5, 2024
@simpleidserver simpleidserver added the enhancement New feature or request label Nov 5, 2024
@simpleidserver simpleidserver moved this to In Progress in Release 5.0.3 Nov 5, 2024
@simpleidserver simpleidserver closed this as completed by moving to Done in Release 5.0.3 Nov 5, 2024
@simpleidserver simpleidserver reopened this Nov 5, 2024
@AcTeemo
Copy link
Author

AcTeemo commented Nov 6, 2024

Thank you for your reply. This should be helpful for me, but I have one question: I'm not sure if there is a FriendlyName attribute, because I can't see the ResponseXml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants