-
Notifications
You must be signed in to change notification settings - Fork 0
/
cognito.clj
38 lines (30 loc) · 1.18 KB
/
cognito.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns hydrogen.module.session.cognito
(:require [duct.core :as core]
[duct.core.env :as env]
[integrant.core :as ig]))
(defn project-ns [config options]
(:project-ns options (:duct.core/project-ns config)))
(defn- session-config-base [project-ns]
{(keyword (str project-ns ".api/config"))
{:cognito
{:iss (env/env '["OIDC_ISSUER_URL" Str])
:client-id (env/env '["OIDC_AUDIENCE" Str])}}
:magnet.buddy-auth/jwt-oidc
{:claims
{:iss (env/env '["OIDC_ISSUER_URL" Str])
:aud (env/env '["OIDC_AUDIENCE" Str])}
:jwks-uri (env/env '["OIDC_JWKS_URI" Str])}
:duct.middleware.buddy/authentication
{:backend :token
:token-name "Bearer"
:authfn (ig/ref :magnet.buddy-auth/jwt-oidc)}})
(defn- session-config [options project-ns]
(cond->
(session-config-base project-ns)
(:add-example-api? options)
(assoc (keyword (str project-ns ".api/example"))
{:auth-middleware (ig/ref :duct.middleware.buddy/authentication)})))
(defmethod ig/init-key :hydrogen.module/session.cognito [_ options]
(fn [config]
(let [project-ns (project-ns config options)]
(core/merge-configs config (session-config options project-ns)))))