Skip to content

--no-gui and --external-auth generate NameError: name 'prompt_toolkit' is not defined #206

@roboshim

Description

@roboshim

Hello,
I would like to use --no-gui and --external-auth options, because I use TB client ID and TB defined redirect_uri as https://localhost (probably http is denied by MS nowdays). With --local-server-auth and redirect_uri set as https://localhost:22222 I get error

request failed - if this error reoccurs, please check `redirect_uri` for xxxxxxxxxxxxxxxxxxxxx is not specified as `https` mistakenly

No, redirect_uri is set to https, because with http://localhost as redirect_uri the login.microsoftonline.com sends error:

The redirect URI 'http://localhost' specified in the request does not match the redirect URIs configured for the application 'f21dcaf2-8020-469b-8135-343bfc35d046'. Make sure the redirect URI sent in the request matches one added to your application in the Azure portal. Navigate to https://aka.ms/redirectUriMismatchError to learn more about how to fix this

Therefore I would like to make authentication on my own using --no-gui and --external-auth. But if I use these options and the I try to login, I get error:

2023-11-16 15:36:08: Email OAuth 2.0 Proxy No-GUI external auth mode: please authorise a request for account xxxxxxxxxxxxxxxxxxxxx
Traceback (most recent call last):
  File ".../email-oauth2-proxy/emailproxy.py", line 3168, in <module>
    App()
  File ".../email-oauth2-proxy/emailproxy.py", line 2358, in __init__
    self.post_create(None)
  File ".../email-oauth2-proxy/emailproxy.py", line 3094, in post_create
    self.terminal_external_auth_prompt(data)
  File ".../email-oauth2-proxy/emailproxy.py", line 3056, in terminal_external_auth_prompt
    prompt_session = prompt_toolkit.PromptSession()
                     ^^^^^^^^^^^^^^
NameError: name 'prompt_toolkit' is not defined

There is a code in App.__init()__

if not self.args.gui and self.args.external_auth:
    try:
        import prompt_toolkit
    except ImportError:
        self.exit(None)
        return

But somehow the prompt_toolkit is not visible in App.terminal_external_auth_prompt()

    def terminal_external_auth_prompt(self, data):
        prompt_session = prompt_toolkit.PromptSession()

The import prompt_toolkit is probably not global. I have tried to define prompt_toolkit as global in App.__init__()

def __init__(self, args=None):
    global CONFIG_FILE_PATH, CACHE_STORE, EXITING, prompt_toolkit

and now I get URL to login and no error.

I have created PR, if you could merge it. Thank you.

Regards,

Robo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions