Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows compatibility #16

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ in
}
```

### Windows

Install with pip/pipx and be sure that you have `sudo` and `openconnect` executables
in your PATH.

## Configuration

If you want to save credentials and get them automatically
Expand Down
17 changes: 7 additions & 10 deletions openconnect_sso/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import getpass
import json
import logging
import os
import shlex
import signal
from pathlib import Path
Expand All @@ -25,6 +26,8 @@ def run(args):
configure_logger(logging.getLogger(), args.log_level)

try:
if os.name == 'nt':
asyncio.set_event_loop(asyncio.ProactorEventLoop())
return asyncio.get_event_loop().run_until_complete(_run(args))
except KeyboardInterrupt:
logger.warn("CTRL-C pressed, exiting")
Expand Down Expand Up @@ -141,20 +144,14 @@ async def run_openconnect(auth_info, host, args):
command_line = [
"sudo",
"openconnect",
"--cookie-on-stdin",
"--cookie",
auth_info.session_token,
"--servercert",
auth_info.server_cert_hash,
*args,
host.vpn_url,
]

logger.debug("Starting OpenConnect", command_line=command_line)
proc = await asyncio.create_subprocess_exec(
*command_line,
host.vpn_url,
stdin=asyncio.subprocess.PIPE,
stdout=None,
stderr=None,
)
proc.stdin.write(f"{auth_info.session_token}\n".encode())
await proc.stdin.drain()
proc = await asyncio.create_subprocess_exec(*command_line)
await proc.wait()