Skip to content

Commit 18d3473

Browse files
committed
Merge branch 'docker-support' into dev
2 parents f7a25f4 + 216e78f commit 18d3473

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

msal/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def _acquire_token_interactive(app, scopes=None, data=None):
107107
enable_msa_passthrough=app.client_id in [ # Apps are expected to set this right
108108
_AZURE_CLI, _VISUAL_STUDIO,
109109
], # Here this test app mimics the setting for some known MSA-PT apps
110+
port=1234, # Hard coded for testing. Real app typically uses default value.
110111
prompt=prompt, login_hint=login_hint, data=data or {},
111112
)
112113
if login_hint and "id_token_claims" in result:

msal/oauth2cli/authcode.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
After obtaining an auth code, the web server will automatically shut down.
77
"""
88
import logging
9+
import os
910
import socket
1011
import sys
1112
from string import Template
@@ -38,6 +39,20 @@ def obtain_auth_code(listen_port, auth_uri=None): # Historically only used in t
3839
).get("code")
3940

4041

42+
def _is_inside_docker():
43+
try:
44+
with open("/proc/1/cgroup") as f: # https://stackoverflow.com/a/20012536/728675
45+
# Search keyword "/proc/pid/cgroup" in this link for the file format
46+
# https://man7.org/linux/man-pages/man7/cgroups.7.html
47+
for line in f.readlines():
48+
cgroup_path = line.split(":", 2)[2].strip()
49+
if cgroup_path.strip() != "/":
50+
return True
51+
except IOError:
52+
pass # We are probably not running on Linux
53+
return os.path.exists("/.dockerenv") # Docker on Mac will run this line
54+
55+
4156
def is_wsl():
4257
# "Official" way of detecting WSL: https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364
4358
# Run `uname -a` to get 'release' without python
@@ -165,7 +180,7 @@ def __init__(self, port=None, scheduled_actions=None):
165180
then the receiver would call that lambda function after
166181
waiting the response for 10 seconds.
167182
"""
168-
address = "127.0.0.1" # Hardcode, for now, Not sure what to expose, yet.
183+
address = "0.0.0.0" if _is_inside_docker() else "127.0.0.1" # Hardcode
169184
# Per RFC 8252 (https://tools.ietf.org/html/rfc8252#section-8.3):
170185
# * Clients should listen on the loopback network interface only.
171186
# (It is not recommended to use "" shortcut to bind all addr.)
@@ -283,13 +298,15 @@ def _get_auth_response(self, result, auth_uri=None, timeout=None, state=None,
283298
logger.warning(
284299
"Found no browser in current environment. "
285300
"If this program is being run inside a container "
286-
"which has access to host network "
301+
"which either (1) has access to host network "
287302
"(i.e. started by `docker run --net=host -it ...`), "
303+
"or (2) published port {port} to host network "
304+
"(i.e. started by `docker run -p 127.0.0.1:{port}:{port} -it ...`), "
288305
"you can use browser on host to visit the following link. "
289306
"Otherwise, this auth attempt would either timeout "
290307
"(current timeout setting is {timeout}) "
291308
"or be aborted by CTRL+C. Auth URI: {auth_uri}".format(
292-
auth_uri=_uri, timeout=timeout))
309+
auth_uri=_uri, timeout=timeout, port=self.get_port()))
293310
else: # Then it is the auth_uri_callback()'s job to inform the user
294311
auth_uri_callback(_uri)
295312

0 commit comments

Comments
 (0)