metabase / saml20-clj

A Clojure SAML 2.0 library for SSO
35 stars 11 forks source link

saml20-clj.sp.request Coerce/->Element throws [samlp:AuthnRequest: null] #64

Open MMaicki opened 1 year ago

MMaicki commented 1 year ago

This part is working just fine and returning XML just as it should:

(coerce/->xml-string
                                   [:samlp:AuthnRequest
                                    {:xmlns:samlp                 "urn:oasis:names:tc:SAML:2.0:protocol"
                                     :ID                          request-id
                                     :Version                     "2.0"
                                     :IssueInstant                (format-instant instant)
                                     :ProtocolBinding             "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
                                     :ProviderName                sp-name
                                     :IsPassive                   false
                                     :Destination                 idp-url
                                     :AssertionConsumerServiceURL acs-url}
                                    [:saml:Issuer
                                     {:xmlns:saml "urn:oasis:names:tc:SAML:2.0:assertion"}
                                     issuer]
                                    ;;[:samlp:NameIDPolicy {:AllowCreate false :Format saml-format}]
                                    ])

XML that it produces looks like this, which looks fine:

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
 <samlp:AuthnRequest 
 AssertionConsumerServiceURL=\"https://www.mydomain.com/saml\" 
 Destination=\"https://login.microsoftonline.com/rand0m-saml2-ap1-id/saml2\" 
 ID=\"999888\" IssueInstant=\"111222\" 
 ProtocolBinding=\"urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST\" 
 ProviderName=\"MyFancyApp\" 
 Version=\"2.0\" 
 xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\">
 <saml:Issuer xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\">
 https://login.microsoftonline.com/rand0m-saml2-ap1-id/federationmetadata/2007-06/federationmetadata.xml
 </saml:Issuer>
 </samlp:AuthnRequest>

But coerce/->Element returns #object[com.sun.org.apache.xerces.internal.dom.DeferredElementNSImpl 0x6db903b4 "[samlp:AuthnRequest: null]"] which is bad as it should have values from the XML instead of NULL.

(coerce/->Element (coerce/->xml-string
                                   [:samlp:AuthnRequest
                                    {:xmlns:samlp                 "urn:oasis:names:tc:SAML:2.0:protocol"
                                     :ID                          request-id
                                     :Version                     "2.0"
                                     :IssueInstant                (format-instant instant)
                                     :ProtocolBinding             "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
                                     :ProviderName                sp-name
                                     :IsPassive                   false
                                     :Destination                 idp-url
                                     :AssertionConsumerServiceURL acs-url}
                                    [:saml:Issuer
                                     {:xmlns:saml "urn:oasis:names:tc:SAML:2.0:assertion"}
                                     issuer]
                                    ;;[:samlp:NameIDPolicy {:AllowCreate false :Format saml-format}]
                                    ]))

I was following README guide and this error breaks everything.

camsaul commented 1 year ago

Hmmm, that's weird. Did you dig in to this at all? PRs welcome

camsaul commented 1 year ago

What version of the lib are you using? We fixed support for non-saml namespaces in 2.1.0, so this wouldn't have worked in prior versions because the namespace above is samlp

MMaicki commented 1 year ago

I'm using [metabase/saml20-clj "2.1.0"]

I don't have PR. I was trying to migrate from kirasystems/saml20-clj lib and I was creating a POC.

I hoped for this lib to work out of the box.