Skip to content

Commit

Permalink
Added ooapi version (#8)
Browse files Browse the repository at this point in the history
* Added support for env OOAPI_VERSION

* Fixed conext auth call; added accept header
  • Loading branch information
mdemare authored Sep 13, 2024
1 parent 9f12ffe commit f0933e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ GATEWAY_BASIC_AUTH_PASS Password for gateway
SURF_CONEXT_CLIENT_ID SurfCONEXT client id for validation service
SURF_CONEXT_CLIENT_SECRET SurfCONEXT client secret for validation service
SURF_CONEXT_INTROSPECTION_ENDPOINT SurfCONEXT introspection endpoint
OOAPI_VERSION Ooapi version to pass through to gateway
```

## Build
Expand Down
7 changes: 5 additions & 2 deletions src/nl/surf/eduhub/validator/service/authentication.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
(string? token)
(map? auth)]}
(try
(let [opts {:basic-auth auth :form-params {:token token} :throw false}
(let [opts {:basic-auth auth
:form-params {:token token}
:throw false
:headers {"Accept" "application/json"}}
{:keys [status] :as response} (http/post uri opts)]
(when (= http-status/ok status)
;; See RFC 7662, section 2.2
Expand All @@ -84,7 +87,7 @@
(fn [token]
(authenticate-token introspection-endpoint
token
{:basic-auth auth})))
auth)))

(defn handle-request-with-token [request request-handler client-id]
(if (nil? client-id)
Expand Down
12 changes: 7 additions & 5 deletions src/nl/surf/eduhub/validator/service/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]
[ring.middleware.json :refer [wrap-json-response]]))

(defn validate-endpoint [endpoint-id config]
(defn validate-endpoint [endpoint-id {:keys [gateway-url gateway-basic-auth ooapi-version] :as _config}]
(log/info "validating endpoint: " endpoint-id)
(try
(let [response (http/get (str (:gateway-url config) "courses")
(let [response (http/get (str gateway-url "courses")
{:headers {"x-route" (str "endpoint=" endpoint-id)
"accept" "application/json; version=5"
"accept" (str "application/json; version=" ooapi-version)
"x-envelope-response" "false"}
:basic-auth (:gateway-basic-auth config)
:basic-auth gateway-basic-auth
:throws false})]
(if (= (:status response) 200)
{:valid true}
Expand Down Expand Up @@ -74,7 +74,9 @@
:surf-conext-client-secret ["SurfCONEXT client secret for validation service" :str
:in [:introspection-basic-auth :pass]]
:surf-conext-introspection-endpoint ["SurfCONEXT introspection endpoint" :str
:in [:introspection-endpoint-url]]})
:in [:introspection-endpoint-url]]
:ooapi-version ["Ooapi version to pass through to gateway" :str
:in [:ooapi-version]]})

(defn start-server [routes]
(let [server (run-jetty routes {:port 3002 :join? false})
Expand Down

0 comments on commit f0933e4

Please sign in to comment.