Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weikanglim opened this issue Dec 8, 2022 · 15 comments

Comments

@weikanglim
Copy link
Contributor

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.

@ghost ghost added the needs-triage For new issues label Dec 8, 2022
@ghost ghost removed the needs-triage For new issues label Dec 14, 2022
@rajeshkamal5050 rajeshkamal5050 added this to the On Deck milestone Dec 14, 2022
@KSchlobohm
Copy link

@weikanglim +1 for WSL experience

@pdebruin
Copy link

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

@vhvb1989
Copy link
Member

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

@vhvb1989
Copy link
Member

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
Copy link
Member

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

@weikanglim
Copy link
Contributor Author

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

@pdebruin
Copy link

@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
Copy link

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

@weikanglim
Copy link
Contributor Author

@vhvb1989 Was WSL working with interactive browser?

@vhvb1989
Copy link
Member

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

@vhvb1989
Copy link
Member

Also related: #2291

@rajeshkamal5050 rajeshkamal5050 modified the milestones: On Deck, Gallium Jun 13, 2023
@rajeshkamal5050
Copy link
Contributor

@weikanglim @vhvb1989 is this issue still valid with @ellismg MSAL changes to override the package used for browser opening? - #2291 (comment)

@GiuseppeGalilei
Copy link

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

@mitchdenny
Copy link

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants