FreeRDP
Loading...
Searching...
No Matches
freerdp_aad_handler Namespace Reference

Functions

int main ()
 

Detailed Description

Prototype: invoked by the desktop environment (via a .desktop file
registered as the handler for x-scheme-handler/ms-appx-web) when a browser
hands off a ms-appx-web:// navigation to the OS.

Pulls the freerdp_id out of the *state* query parameter (Azure wants a
redirect_uri that is exactly ms-appx-web://Microsoft.AAD.BrokerPlugin/<client_id> -
but state is an app-opaque value the IdP just echoes back verbatim, so the helper prefixes
it with "<freerdp_id>." before sending the user to the IdP) and forwards the
whole URL to that session's local listener over a unix socket named
freerdp_aad_<freerdp_id>.

Expected URL shape:
  ms-appx-web://Microsoft.AAD.BrokerPlugin/<client_id>?code=...&state=<freerdp_id>.<original_state>

Function Documentation

◆ main()

int freerdp_aad_handler.main ( )

Definition at line 22 of file freerdp_aad_handler.py.

22def main() -> int:
23 if len(sys.argv) != 2:
24 print(f"usage: {sys.argv[0]} <url>", file=sys.stderr)
25 return 1
26
27 url = sys.argv[1]
28 parsed = urllib.parse.urlparse(url)
29
30 #with open("/tmp/aad_log.txt", "a") as f:
31 # f.write(f"url={url}\n")
32 # f.write(f"parsed={parsed}\n")
33
34 if parsed.netloc.lower() == "microsoft.aad.brokerplugin":
35 state_values = urllib.parse.parse_qs(parsed.query).get("state")
36 if not state_values:
37 print(f"no state parameter found in {url!r}", file=sys.stderr)
38 return 1
39
40 freerdp_id = state_values[0].split(".", 1)[0]
41 runtime_dir = os.environ.get("XDG_RUNTIME_DIR", "/tmp")
42 sock_path = os.path.join(runtime_dir, f"freerdp_aad_{freerdp_id}.sock")
43
44 try:
45 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
46 sock.connect(sock_path)
47 sock.sendall(url.encode() + b"\n")
48 except OSError as exc:
49 print(f"could not reach {sock_path}: {exc}", file=sys.stderr)
50 return 1
51
52 return 0
53
54