Skip to content

Commit

Permalink
Added export_jwks method and then used it for key rollover in the ser…
Browse files Browse the repository at this point in the history
…ver example.
  • Loading branch information
Roland Hedberg committed Sep 25, 2015
1 parent b32013d commit 37b9dee
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions oidc_example/op2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"upper": "crust"
}

JWKS_FILE_NAME = "static/jwks.json"

# ----------------------------------------------------------------------------

Expand Down Expand Up @@ -254,8 +255,14 @@ def check_session_iframe(environ, start_response, logger):

def key_rollover(environ, start_response, _):
# expects a post containing the necessary information
_jwks = json.loads(get_post(environ))
_txt = get_post(environ)
_jwks = json.loads(_txt)
logger.info("Key rollover to")
OAS.do_key_rollover(_jwks, "key_%d_%%d" % int(time.time()))
# Dump to file
f = open(JWKS_FILE_NAME, "w")
f.write(json.dumps(OAS.keyjar.export_jwks()))
f.close()
resp = Response("OK")
return resp(environ, start_response)

Expand Down Expand Up @@ -583,16 +590,16 @@ def application(environ, start_response):
LOGGER.error("Key setup failed: %s" % err)
OAS.key_setup("static", sig={"format": "jwk", "alg": "rsa"})
else:
new_name = "static/jwks.json"
f = open(new_name, "w")
jwks_file_name = JWKS_FILE_NAME
f = open(jwks_file_name, "w")

for key in jwks["keys"]:
for k in key.keys():
key[k] = as_unicode(key[k])

f.write(json.dumps(jwks))
f.close()
OAS.jwks_uri.append("%s%s" % (OAS.baseurl, new_name))
OAS.jwks_uri.append("%s%s" % (OAS.baseurl, jwks_file_name))

for b in OAS.keyjar[""]:
LOGGER.info("OC3 server keys: %s" % b)
Expand Down

0 comments on commit 37b9dee

Please sign in to comment.