codekingpro/portable-devtools
114k
1from authlib.common.urls import urlparse2 3 4def get_well_known_url(issuer, external=False, suffix='oauth-authorization-server'):5 """Get well-known URI with issuer via `Section 3.1`_.6 7 .. _`Section 3.1`: https://tools.ietf.org/html/rfc8414#section-3.18 9 :param issuer: URL of the issuer10 :param external: return full external url or not11 :param suffix: well-known URI suffix for RFC841412 :return: URL13 """14 parsed = urlparse.urlparse(issuer)15 path = parsed.path16 if path and path != '/':17 url_path = f'/.well-known/{suffix}{path}'18 else:19 url_path = f'/.well-known/{suffix}'20 if not external:21 return url_path22 return parsed.scheme + '://' + parsed.netloc + url_path23 