File: well_known.py

package info (click to toggle)
python-authlib 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: python: 26,998; makefile: 53; sh: 14
file content (22 lines) | stat: -rw-r--r-- 727 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from authlib.common.urls import urlparse


def get_well_known_url(issuer, external=False, suffix="oauth-authorization-server"):
    """Get well-known URI with issuer via `Section 3.1`_.

    .. _`Section 3.1`: https://tools.ietf.org/html/rfc8414#section-3.1

    :param issuer: URL of the issuer
    :param external: return full external url or not
    :param suffix: well-known URI suffix for RFC8414
    :return: URL
    """
    parsed = urlparse.urlparse(issuer)
    path = parsed.path
    if path and path != "/":
        url_path = f"/.well-known/{suffix}{path}"
    else:
        url_path = f"/.well-known/{suffix}"
    if not external:
        return url_path
    return parsed.scheme + "://" + parsed.netloc + url_path