target_audience

igwn_auth_utils.scitokens.target_audience(url, include_any=True)

Return the expected aud claim to authorize a request to url.

Parameters:
  • url (str) – The URL that will be requested.

  • include_any (bool, optional) – If True, include "ANY" in the return list of audiences, otherwise, don’t.

Returns:

audiences – A list of audience values (str), either of length 1 if include_any=False, otherwise of length 2.

Return type:

list of str

Examples

>>> default_audience(
...     "https://datafind.ligo.org:443/LDR/services/data/v1/gwf.json",
...     include_any=True,
... )
["https://datafind.ligo.org", "ANY"]
>>> default_audience(
...     "segments.ligo.org",
...     include_any=False,
... )
["https://segments.ligo.org"]

Hostnames given without a URL scheme are presumed to be HTTPS:

>>> default_audience("datafind.ligo.org")
["https://datafind.ligo.org"]