MCPcopy Create free account
hub / github.com/crewjam/saml / MakeAttributeQuery

Method MakeAttributeQuery

service_provider_attribute_query.go:90–126  ·  view source on GitHub ↗

MakeAttributeQuery returns an AttributeQuery for the attributes of the subject identified by nameID, addressed to the IdP's SOAP AttributeService (see GetAttributeServiceLocation). It returns ErrNoAttributeService if the IdP metadata has none, and an error matching ErrInsecureSOAPEndpoint if its Loc

(nameID NameID, attributes ...Attribute)

Source from the content-addressed store, hash-verified

88// LogoutSignatureMethod is set or SOAP single logout is offered; set one of
89// them so that the attribute authority can verify the query.
90func (sp *ServiceProvider) MakeAttributeQuery(nameID NameID, attributes ...Attribute) (*AttributeQuery, error) {
91 if sp.IDPMetadata == nil {
92 return nil, errors.New("cannot make an attribute query: IDPMetadata is not set")
93 }
94 destination := sp.GetAttributeServiceLocation(SOAPBinding)
95 if destination == "" {
96 return nil, ErrNoAttributeService
97 }
98 if err := checkSOAPEndpoint(destination, sp.AllowInsecureSOAPEndpoints); err != nil {
99 return nil, fmt.Errorf("cannot make an attribute query: %w", err)
100 }
101 if nameID.Value == "" {
102 return nil, errors.New("cannot make an attribute query: the NameID is empty")
103 }
104 if err := checkRequestedAttributesUnique(attributes); err != nil {
105 return nil, err
106 }
107
108 query := &AttributeQuery{
109 ID: fmt.Sprintf("id-%x", randomBytes(20)),
110 Version: "2.0",
111 IssueInstant: sp.now(),
112 Destination: destination,
113 Issuer: &Issuer{
114 Format: "urn:oasis:names:tc:SAML:2.0:nameid-format:entity",
115 Value: sp.entityID(),
116 },
117 Subject: &Subject{NameID: &nameID},
118 Attributes: attributes,
119 }
120 if !signerutil.IsNil(sp.Key) {
121 if err := sp.SignAttributeQuery(query); err != nil {
122 return nil, err
123 }
124 }
125 return query, nil
126}
127
128// checkRequestedAttributesUnique returns an error if two of attributes have
129// the same Name and NameFormat, which saml-core §3.3.2.3 forbids.

Callers 5

QueryAttributesMethod · 0.95
aqQueryMethod · 0.80

Calls 9

nowMethod · 0.95
entityIDMethod · 0.95
SignAttributeQueryMethod · 0.95
IsNilFunction · 0.92
checkSOAPEndpointFunction · 0.85
randomBytesFunction · 0.70
NewMethod · 0.65

Tested by 4

aqQueryMethod · 0.64