Skip to content

Commit b145d32

Browse files
authored
fix(request): add protocol binding to auth message (#104)
Allow the protocol binding to be supplied to the authn messsage request to work with IdPs that only support one kind of protocol such as Entra. This continues to default to HTTP-Redirect so it is not a breaking change to the library. Release as version 4.1.0
1 parent da64b10 commit b145d32

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
4.1.0

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ services:
2525
- 3001:3001
2626
volumes:
2727
- ./src:/app/src
28+
- ./test:/app/test
2829
- ./e2e:/app/e2e
2930

3031
selenium:

src/saml20_clj/sp/request.clj

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626

2727
(def ^:private -sig-alg "http://www.w3.org/2000/09/xmldsig#rsa-sha1")
2828

29+
(defn- keyword->protocol-binding
30+
[binding-kw]
31+
(condp = binding-kw
32+
:post SAMLConstants/SAML2_POST_BINDING_URI
33+
:redirect SAMLConstants/SAML2_REDIRECT_BINDING_URI
34+
(throw (ex-info "Unsupported protocol binding argument" {:arg binding-kw
35+
:allowed [:redirect :post]}))))
36+
2937
(defn- setup-message-context
3038
[message credential sig-alg idp-url]
3139
(let [msgctx (doto (MessageContext.) (.setMessage message))]
@@ -49,12 +57,12 @@
4957
msgctx))
5058

5159
(defn- build-authn-obj
52-
^AuthnRequest [request-id instant sp-name idp-url acs-url issuer]
60+
^AuthnRequest [request-id instant sp-name idp-url acs-url issuer protocol-binding]
5361
(doto (.buildObject (AuthnRequestBuilder.))
5462
(.setID request-id)
5563
(.setIssueInstant instant)
5664
(.setDestination idp-url)
57-
(.setProtocolBinding SAMLConstants/SAML2_REDIRECT_BINDING_URI)
65+
(.setProtocolBinding (keyword->protocol-binding protocol-binding))
5866
(.setIsPassive false)
5967
(.setProviderName sp-name)
6068
(.setAssertionConsumerServiceURL acs-url)
@@ -73,8 +81,9 @@
7381
state-manager
7482
credential
7583
sig-alg
76-
instant]
77-
(let [request (build-authn-obj request-id instant sp-name idp-url acs-url issuer)]
84+
instant
85+
protocol-binding]
86+
(let [request (build-authn-obj request-id instant sp-name idp-url acs-url issuer protocol-binding)]
7887
(when state-manager
7988
(state/record-request! state-manager (.getID request)))
8089
(setup-message-context request credential sig-alg idp-url)))
@@ -143,14 +152,18 @@
143152
sig-alg
144153
;; relay-state argument that will be returned by the provider
145154
relay-state
155+
;; protocol binding specifying if IdP should use HTTP-Post or HTTP-Redirect to respond
156+
protocol-binding
146157
instant]
147158
:or {instant (t/instant)
148159
request-id (random-request-id)
149-
sig-alg -sig-alg}}]
160+
sig-alg -sig-alg
161+
protocol-binding :redirect}}]
150162
(assert (non-blank-string? acs-url) "acs-url is required")
151163
(assert (non-blank-string? idp-url) "idp-url is required")
152164
(assert (non-blank-string? sp-name) "sp-name is required")
153165
(assert (non-blank-string? issuer) "issuer is required")
166+
(assert (keyword? protocol-binding) "protocol binding must be a keyword")
154167
(redirect-response (authn-request request-id
155168
sp-name
156169
acs-url
@@ -159,7 +172,8 @@
159172
state-manager
160173
credential
161174
sig-alg
162-
instant)
175+
instant
176+
protocol-binding)
163177
relay-state))
164178

165179
(defn idp-logout-redirect-response

test/saml20_clj/sp/request_test.clj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@
6969
"tPvTgWDbY7Io5ENEElvsa8eJziZz3TYtFJa1AUDtO2c6BQX627"
7070
"LA7Y0gCvhj035rxJZPPh8ucdTCjNA0roYFpdlQiKQZnUJmJgX2"
7171
"QvB9Zr7WTIEPXMNkb%2B0%3D")}}
72+
(request/idp-redirect-response request)))))
73+
(testing "with a signature and http post binding"
74+
(let [request {:request-id "ONELOGIN_809707f0030a5d00620c9d9df97f627afe9dcc24"
75+
:sp-name "SP test"
76+
:acs-url "http://sp.example.com/demo1/index.php?acs"
77+
:idp-url "http://idp.example.com/SSOService.php"
78+
:issuer "http://sp.example.com/demo1/metadata.php"
79+
:credential test/sp-private-key
80+
:relay-state target-uri
81+
:protocl-binding :post}]
82+
(is (= {:status 302,
83+
:body "",
84+
:headers
85+
{"Cache-control" "no-cache, no-store"
86+
"Pragma" "no-cache"
87+
"location" (str "http://idp.example.com/SSOService.php?SAMLRequest="
88+
"fVLLbtswEPwVgndJFPNwRFg2nLppDbi2YDk59FIw5KomIJEqlz"
89+
"Lcv4%2BsKEFyiK%2B7OzuzMzudn5qaHMGjcTanacwoAaucNvZv"
90+
"Th%2F3D9Ednc%2BmKJuat2LRhYPdwb8OMJAeaFG8dnLaeSucRI"
91+
"PCygZQBCXKxa%2B14DETrXfBKVdTskAEH3qqb85i14AvwR%2BN"
92+
"gsfdOqeHEFqRJNjGcJJNW0OsXJNoaFyaGKvhFLeHdi4VUrLsBR"
93+
"grwyB6xBn9GViW23H7GUfJapnT7eb7evtjtflzx7IJm1SMXTF5"
94+
"oxm75UxlOtNVNqlu%2BURWkGml%2BHUPw0IimiPktJI1wrmCHa"
95+
"wsBmlDTjnjLGJZxK%2F3nIubVDAWM8Z%2BU1KMZ9%2F34gc7L3"
96+
"n0%2FDqE4ud%2BX0Q70MaDCsOSo9HgNz0ip2VBQn86JU9vifVY"
97+
"OuYjBmH%2BYzCXOeVbGnR2yfsGgtQyyLON0%2BQj1ftjnNWtlo"
98+
"WrjfpPHpxvZPiaOo3ToWJ0VA2jorPYgjKVAU2T2cjx%2Bd1mLw"
99+
"%3D%3D&RelayState=http%3A%2F%2Fsp.example.com%2Fde"
100+
"mo1%2Findex.php%3Facs&SigAlg=http%3A%2F%2Fwww.w3.o"
101+
"rg%2F2000%2F09%2Fxmldsig%23rsa-sha1&Signature=KJSj"
102+
"oD6Mg7OH%2F2pCd6qEDmqSxqWZqOmBePLC5RemNjmLE2ElfnO0"
103+
"tPvTgWDbY7Io5ENEElvsa8eJziZz3TYtFJa1AUDtO2c6BQX627"
104+
"LA7Y0gCvhj035rxJZPPh8ucdTCjNA0roYFpdlQiKQZnUJmJgX2"
105+
"QvB9Zr7WTIEPXMNkb%2B0%3D")}}
72106
(request/idp-redirect-response request)))))))
73107

74108
(deftest idp-logout-redirect-response-test

0 commit comments

Comments
 (0)