diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gn-auth-stub.py | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/scripts/gn-auth-stub.py b/scripts/gn-auth-stub.py index 15d6a18..13489d0 100755 --- a/scripts/gn-auth-stub.py +++ b/scripts/gn-auth-stub.py @@ -43,7 +43,18 @@ as long as anything serving `test/data/test_jwks.json` is up. `iss` has to match genenetwork4's `AUTH_SERVER_URL` exactly (it is passed to `Validation::set_issuer` verbatim), including the trailing slash the default `http://127.0.0.1:8081/` carries -- that is what -`--port`/`--issuer` are for. +`--port`/`--issuer` are for, and why `--issuer` falls back to +`AUTH_SERVER_URL` when that is set in the environment. + +To issue a token for one more user, run a second instance with +`--mint-only` and the *same* issuer as the long-running one: + + scripts/gn-auth-stub.py --mint-only --subject alice \ + --expires-in 30d --token-file /run/gn4/alice.token + +It mints, prints and exits without listening; the token verifies against +the long-running stub, because verification only depends on the key +(committed, therefore shared) and on `iss`. """ import argparse @@ -202,6 +213,14 @@ def main(): "test_jwks.json is up.", ) parser.add_argument( + "--mint-only", + action="store_true", + help="mint the token, print it (and write --token-file) and exit " + "without listening. Mints for --subject with the same key and iss as " + "the long-running stub, so the token verifies against it -- this is " + "how a token is issued for one more user.", + ) + parser.add_argument( "--grant-resource-id", action="append", default=[], @@ -217,11 +236,22 @@ def main(): ) args = parser.parse_args() - issuer = args.issuer or f"http://127.0.0.1:{args.port}/" + issuer = ( + args.issuer + or os.environ.get("AUTH_SERVER_URL") + or f"http://127.0.0.1:{args.port}/" + ) jwks_document = open(JWKS_FILE).read() kid = json.loads(jwks_document)["jwks"][0]["kid"] token = sign(issuer, kid, args.subject, args.scope, args.expires_in) + if args.mint_only: + if args.token_file: + with open(args.token_file, "w") as handle: + handle.write(token + "\n") + print(token, flush=True) + return + # Bind before writing or printing anything: a second instance started # while one is already listening fails here, and must leave the first # one's token file alone rather than clobber it with a token nothing |
