add_http_authorization_header#

gwpy.io.scitokens.add_http_authorization_header(
headers: MutableMapping,
*,
token: SciToken | None = None,
error: bool = True,
url: str | None = None,
audience: str | None = None,
create: bool = True,
**claims,
) None[source]#

Try and generate an HTTP Authorization header for a SciToken.

This function tries to find an existing token that matches the required claims, otherwise will attempt to create (acquire) a new token.

That token is then serialised to create the argument for an Authorization header using the Bearer scheme.

Parameters:
headersdict

The dict in which to store the Authorization header.

urlstr, optional

The URL for which to attempt to find an existing token (to match the audience claim).

errorbool, optional

If True raise exceptions if tokens cannot be found or generated.

tokenscitokens.SciToken, optional

A deserialised token to use for the header.

audiencestr, optional

The required value for the aud claim.

createbool, optional

If True, attempt to create (acquire) a new token if an existing token is not found.

claims

Other keyword arguments are passed as claims to requests_scitokens.HTTPSciTokenAuth.find_token or gwpy.io.scitokens.get_scitoken.

See also

requests_scitokens.HTTPSciTokenAuth.find_token

For details on how tokens are discovered.

gwpy.io.scitokens.get_scitoken

For details on how tokens are created (acquired).