|
11 | 11 | from urllib import urlencode |
12 | 12 |
|
13 | 13 |
|
14 | | -def build_auth_endpoint(tenant, client_id): # Microsoft specific |
15 | | - return ( # Lucky that redirect_uri can be omitted, so it works for any app |
16 | | - "https://login.microsoftonline.com/{t}/oauth2/authorize" # V1 endpoint |
17 | | - "?response_type=code&client_id={c}").format(t=tenant, c=client_id) |
| 14 | +def build_auth_url(authority, client_id): |
| 15 | + # Lucky that redirect_uri can be omitted, so it works for any app |
| 16 | + return "{a}/oauth2/authorize?response_type=code&client_id={c}".format( |
| 17 | + a=authority, c=client_id) |
18 | 18 |
|
19 | 19 | class AuthCodeReceiver(BaseHTTPRequestHandler): |
20 | 20 | """A one-stop solution to acquire an authorization code. |
@@ -67,10 +67,11 @@ def send_full_response(self, body, is_ok=True): |
67 | 67 | p = parser = argparse.ArgumentParser( |
68 | 68 | description=AuthCodeReceiver.__doc__ |
69 | 69 | + "The auth code received will be dumped into stdout.") |
70 | | - p.add_argument('tenant', help="The tenant which your app will serve for") |
71 | 70 | p.add_argument('client_id', help="The client_id of your web service app") |
72 | 71 | p.add_argument('redirect_port', type=int, help="The port in redirect_uri") |
| 72 | + p.add_argument( |
| 73 | + "--authority", default="https://login.microsoftonline.com/common") |
73 | 74 | args = parser.parse_args() |
74 | 75 | print(AuthCodeReceiver.acquire( |
75 | | - build_auth_endpoint(args.tenant, args.client_id), args.redirect_port)) |
| 76 | + build_auth_url(args.authority, args.client_id), args.redirect_port)) |
76 | 77 |
|
0 commit comments