-
Notifications
You must be signed in to change notification settings - Fork 0
/
discovery.clj
33 lines (29 loc) · 1009 Bytes
/
discovery.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
(ns com.yetanalytics.pedestal-oidc.discovery
"OIDC discovery https://openid.net/specs/openid-connect-discovery-1_0.html"
(:require [clojure.spec.alpha :as s]
[cheshire.core :as json]
[clojure.java.io :as io]
[clojure.string :as cstr]))
(s/fdef issuer->config-uri
:args (s/cat :issuer string?)
:ret string?)
(defn issuer->config-uri
[issuer]
(str issuer
(when-not (cstr/ends-with? issuer "/")
"/")
".well-known/openid-configuration"))
(s/fdef get-openid-config
:args (s/cat :config-uri string?)
:ret map?)
(defn get-openid-config
[config-uri
& {:keys [key-fn]
:or {key-fn str}}]
(try (with-open [rdr (io/reader (io/input-stream config-uri))]
(json/parse-stream rdr key-fn))
(catch Exception ex
(throw (ex-info "Could not retrieve openid configuration!"
{:type ::get-openid-config-fail
:config-uri config-uri}
ex)))))