Ring middleware that adds OIDC session handling (userinfo
and end_session
endpoints).
Based on and to be used together with ring-oauth2.
The middleware function to use is ring-oidc-session/wrap-oidc-session
.
ring-oauth2
profile map:(require '[ring-oidc-session :refer [wrap-oidc-session]])
(-> handler
(wrap-oidc-session
{:your-oidc-provider
{; ... other ring-oauth2 options...
:userinfo-uri "{oidc_idp_domain}/oidc/v1/userinfo"
:end-session-uri "{oidc_idp_domain}/oidc/v1/end_session"
:logout-oidc-uri "/your/end-oidc-session/route"
:logout-ring-uri "/your/logout/route"
})
)
wrap-oidc-session
uses the config to add one request-modifying middleware and 3 ring routes
A request-modifying middleware will be applied to the :landing-uri
route:
:ring.middleware.oauth2/access-tokens
are found in the :session
key of the request then the OIDC userinfo endpoint (:userinfo-uri
) will be queried.
:your-oidc-provider
, above) will be used to find the profile with the :userinfo-uri
.::userinfo
.::userinfo
request key will be associated with a nil
value.A :logout-oidc-uri
route will be added which will clear the ring session and redirect the user to the OIDC end_session endpoint (:end-session-uri
).
A :logout-ring-uri
route will be added which will clear the ring session (but leave the OIDC IdP session intact).
This should be placed above the wrap-oauth2
handler, where oidc-profile-map
in the merged profile map of oauth2 and oidc-session data above:
...middleware...
(wrap-oidc-session oidc-profile-map)
(wrap-oauth2 oidc-profile-map)
...middleware...
State mismatch
error, you likely need to add SameSite:Lax
cookie option
to allow for cross-site GET cookie for auth state.
(wrap-defaults (-> ringdef/site-defaults (assoc-in [:session :cookie-attrs :same-site] :lax)))
(wrap-params)
Invoke a library API function from the command-line:
$ clojure -X com.halo9000.ring-oidc-session/foo :a 1 :b '"two"'
{:a 1, :b "two"} "Hello, World!"
Run the project's tests (they'll fail until you edit them):
$ clojure -T:build test
Run the project's CI pipeline and build a JAR (this will fail until you edit the tests to pass):
$ clojure -T:build ci
This will produce an updated pom.xml
file with synchronized dependencies inside the META-INF
directory inside target/classes
and the JAR in target
. You can update the version (and SCM tag)
information in generated pom.xml
by updating build.clj
.
Install it locally (requires the ci
task be run first):
$ clojure -T:build install
Apply (and push) the version tag to the git repo:
$ clojure -T:build git-tag-version
Deploy it to Clojars -- needs CLOJARS_USERNAME
and CLOJARS_PASSWORD
environment
variables (requires the ci
task be run first):
$ clojure -T:build deploy
Your library will be deployed to com.halo9000/ring-oidc-session on clojars.org by default.
See test-coverage
Run tests and produce fully annotatated source coverage report in target/coverage/
:
clj -M:test:coverage
firefox target/coverage/index.html
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close