Skip to content

Commit

Permalink
Fix ability to handle long auth code URLs for O365 with tenant (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
MShekow authored Sep 2, 2023
1 parent 8dca283 commit abd9433
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,16 @@ def _get_consent_callback(self, consent_url: str) -> str:
typer.echo(
"After you logged into your Microsoft account and granted consent, your browser should have redirected "
"you to a web page that shows the code that you need to paste here")
return typer.prompt("On the page, please click the 'Copy' button, then "
"paste the clipboard content here, then press Enter",
prompt_suffix='\n')
pasted_code: str = typer.prompt("On the page, please click the 'Copy' button, then "
"paste the clipboard content here, then press Enter", prompt_suffix='\n')

# On macOS, the Terminal only allows pasting content with up to 1024 characters. When the Azure app
# registration requires a tenant, the returned URL (that contains the OAuth authorization code) has 1046
# characters. We work around this problem by omitting the value of OUTLOOK365_REDIRECT_URL (43 chars) in the
# pasted content, adding it here. This saves just enough characters to stay below the 1024 limit.
if not pasted_code.startswith(OUTLOOK365_REDIRECT_URL):
return OUTLOOK365_REDIRECT_URL + "/" + pasted_code
return pasted_code

def _get_calendar_name(self, calendars: list[Calendar]) -> str:
calendar_names = [calendar.name for calendar in calendars]
Expand Down

0 comments on commit abd9433

Please sign in to comment.