Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very rough draft for supporting both keycloak and cas #187

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion policy/diamond/policy/token/token.rego
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
package diamond.policy.token

Check failure on line 1 in policy/diamond/policy/token/token.rego

View workflow job for this annotation

GitHub Actions / lint

File should be formatted with `opa fmt`. To learn more, see: https://docs.styra.com/regal/rules/style/opa-fmt

import rego.v1

verify(token) := profile.sub if {
verify_cas(token) := profile.sub if {
profile := http.send({
"url": opa.runtime().env.USERINFO_ENDPOINT,
"method": "GET",
"headers": {"authorization": token},
})
}

verify_keycloak(token) := claims if {

fetch_jwks(url) := http.send({
"url": jwks_url,
"method": "GET",
"force_cache": true,
"force_cache_duration_seconds": 86400,
})

jwks_endpoint := opa.runtime().env.JWKS_ENDPOINT

unverified := io.jwt.decode(token)

jwt_header := unverified[0]

jwks_url := concat("?", [jwks_endpoint, urlquery.encode_object({"kid": jwt_header.kid})])

jwks := fetch_jwks(jwks_url).raw_body

valid := io.jwt.decode_verify(token, {
"cert": jwks,
"iss": "https://authn.diamond.ac.uk/realms/master",
"aud": "account",
})

claims := valid[2]

}

verify if verify_cas(input.token)
verify if verify_keycloak(input.token)
Loading