Skip to content

Commit

Permalink
Add Content-Type header to default handlers
Browse files Browse the repository at this point in the history
Fixes #53.
  • Loading branch information
weavejester committed Jul 8, 2024
1 parent 087c331 commit 551475e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/ring/middleware/oauth2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,17 @@

(defn state-mismatch-handler
([_]
{:status 400, :headers {}, :body "State mismatch"})
{:status 400
:headers {"Content-Type" "text/plain; charset=utf-8"}
:body "OAuth2 error: state mismatch"})
([request respond _]
(respond (state-mismatch-handler request))))

(defn no-auth-code-handler
([_]
{:status 400, :headers {}, :body "No authorization code"})
{:status 400
:headers {"Content-Type" "text/plain; charset=utf-8"}
:body "OAuth2 error: no authorization code"})
([request respond _]
(respond (no-auth-code-handler request))))

Expand Down
8 changes: 6 additions & 2 deletions test/ring/middleware/oauth2_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@
(assoc :query-params {"code" "abcabc"
"state" "xyzxya"}))
response (test-handler request)]
(is (= {:status 400, :headers {}, :body "State mismatch"}
(is (= {:status 400
:headers {"Content-Type" "text/plain; charset=utf-8"}
:body "OAuth2 error: state mismatch"}
response))))

(testing "custom state mismatched error"
Expand All @@ -162,7 +164,9 @@
(assoc :session {::oauth2/state "xyzxyz"})
(assoc :query-params {"state" "xyzxyz"}))
response (test-handler request)]
(is (= {:status 400, :headers {}, :body "No authorization code"}
(is (= {:status 400
:headers {"Content-Type" "text/plain; charset=utf-8"}
:body "OAuth2 error: no authorization code"}
response))))

(testing "custom no authorization code error"
Expand Down

0 comments on commit 551475e

Please sign in to comment.