azure-dev icon indicating copy to clipboard operation
azure-dev copied to clipboard

`azd login` should fallback to or hint at device code if no browser is found

Open weikanglim opened this issue 3 years ago • 15 comments

Currently, azd login fails with the following error if no browser is installed on Linux:

@weikanglim ➜ /workspaces/todo-python-mongo (main ✗) $ azd login

ERROR: logging in: exec: "xdg-open,x-www-browser,www-browser": executable file not found in $PATH

This would be a common scenario for devcontainers without xdg-utils installed.

We should either fallback to device code login or provide user hints to try device code login as a fallback.

weikanglim avatar Dec 08 '22 20:12 weikanglim

@weikanglim +1 for WSL experience

KSchlobohm avatar Jan 20 '23 20:01 KSchlobohm

Just tried this. Works smooth in codespaces. Should be like that in WSL too.

pdebruin avatar May 12 '23 09:05 pdebruin

@pdebruin are you getting an error in WSL? Can you share it?

vhvb1989 avatar May 12 '23 17:05 vhvb1989

This would be a common scenario for devcontainers without xdg-utils installed.

@weikanglim we should update azd to use https://github.com/pkg/browser for opening a browser. This is what msal is using for interactive login. It would give us 2 more providers on linux:

func openBrowser(url string) error {
	providers := []string{"xdg-open", "x-www-browser", "www-browser"}

	// There are multiple possible providers to open a browser on linux
	// One of them is xdg-open, another is x-www-browser, then there's www-browser, etc.
	// Look for one that exists and run it
	for _, provider := range providers {
		if _, err := exec.LookPath(provider); err == nil {
			return runCmd(provider, url)
		}
	}

	return &exec.Error{Name: strings.Join(providers, ","), Err: exec.ErrNotFound}
}

vhvb1989 avatar May 12 '23 18:05 vhvb1989

Moving to https://github.com/pkg/browser will also help us during cloudshell interactive login

vhvb1989 avatar May 12 '23 18:05 vhvb1989

@vhvb1989 Do you see a custom usage in azd somewhere? IIRC, we are relying on msal, which in turn relies on pkg/browser.

weikanglim avatar May 12 '23 21:05 weikanglim

@pdebruin are you getting an error in WSL? Can you share it?

=== Yes, see below:

$ azd init --template todo-java-mongo-aca

Initializing a new project (azd init)

(✓) Done: Initialized git repository (✓) Done: Downloading template code to: ~/_projects/azdwsl2

? Please enter a new environment name: azdwsl2-dev

SUCCESS: New project initialized! You can view the template code in your directory: ~/_projects/azdwsl2 Learn more about running 3rd party code on our DevHub: https://learn.microsoft.com/azure/developer/azure-developer-cli/azd-templates#guidelines-for-using-azd-templates

$ azd up Error: not logged in, run azd auth login to login

$ azd auth login /usr/bin/xdg-open: 882: x-www-browser: not found /usr/bin/xdg-open: 882: firefox: not found /usr/bin/xdg-open: 882: iceweasel: not found /usr/bin/xdg-open: 882: seamonkey: not found /usr/bin/xdg-open: 882: mozilla: not found /usr/bin/xdg-open: 882: epiphany: not found /usr/bin/xdg-open: 882: konqueror: not found /usr/bin/xdg-open: 882: chromium: not found /usr/bin/xdg-open: 882: chromium-browser: not found /usr/bin/xdg-open: 882: google-chrome: not found /usr/bin/xdg-open: 882: www-browser: not found /usr/bin/xdg-open: 882: links2: not found /usr/bin/xdg-open: 882: elinks: not found /usr/bin/xdg-open: 882: links: not found /usr/bin/xdg-open: 882: lynx: not found /usr/bin/xdg-open: 882: w3m: not found xdg-open: no method available for opening 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=&code_challenge=&code_challenge_method=S256&prompt=select_account&redirect_uri=http%3A%2F%2Flocalhost%3A38713&response_type=code&scope=https%3A%2F%2Fmanagement.azure.com%2F%2F.default+openid+offline_access+profile&state='

ERROR: logging in: exit status 3

=== Tried to repro on second machine, which responded with

ERROR: logging in: exec: "xdg-open,x-www-browser,www-browser": executable file not found in $PATH

===

Hope that helps

pdebruin avatar May 15 '23 13:05 pdebruin

Congrats on the release! 🎉 For completeness, anyone visiting this issue should get azd in wsl to work using: azd auth login --use-device-code azd auth login --check-status

pdebruin avatar May 24 '23 04:05 pdebruin

@vhvb1989 Was WSL working with interactive browser?

weikanglim avatar May 24 '23 17:05 weikanglim

Yes, it works, but it depends on xdg-open + BROWSER config or on installing wslu (https://github.com/wslutilities/wslu)

vhvb1989 avatar May 24 '23 17:05 vhvb1989

Also related: https://github.com/Azure/azure-dev/issues/2291

vhvb1989 avatar May 24 '23 17:05 vhvb1989

@weikanglim @vhvb1989 is this issue still valid with @ellismg MSAL changes to override the package used for browser opening? - https://github.com/Azure/azure-dev/issues/2291#issuecomment-1561666398

rajeshkamal5050 avatar Jun 13 '23 00:06 rajeshkamal5050

Apparently this isn't yet solved. Today I came across a similar issue (https://github.com/Azure-Samples/azure-search-openai-demo/issues/1855) executing azd auth login from a GitHub codespace terminal. As suggested here (https://github.com/Azure/azure-cli/issues/20315) azd auth login --use-device-code solved the issue.

GiuseppeGalilei avatar Jul 23 '24 18:07 GiuseppeGalilei

@ellismg @vhvb1989 I came across this as well whilst I was getting Codespaces up and running from the dotnet/aspire repo. Luckily I knew the device code URL because otherwise there is no hint:

Image

mitchdenny avatar Oct 26 '24 09:10 mitchdenny

Actually, if I read that again, and I press enter it pops the browser. I think it would be better to do what other login experiences do and just put up the devicelogin URL.

mitchdenny avatar Oct 26 '24 09:10 mitchdenny