I was getting this weird error on my local Sitecore Docker setup setting up from scratch. The funny thing was the Sitecore and login page was working fine in the browser but not from PowerShell/Command Prompt as I was getting this error
D:\Projects\STB\Source>dotnet sitecore login --authority https://id.stbcom.localhost --cm https://cm.stbcom.localhost --allow-write true
Error discovering identity provider. Perhaps the authority hostname, https://id.stbcom.localhost/, is not valid or it is not serving OpenID metadata (/.well-known/openid-configuration).
The things that were really frustrating were
- The identity server was working and accessible via URL in the browser https://id.stbcom.localhost
- I was able to login to CM using https://cm.stbcom.localhost which was redirecting to identity URL and then back to CM logged-in.
- I was able to access https://id.stbcom.localhost/.well-known/openid-configuration just fine in browser.
After googling around I did not find anything useful, there were couple of posts but this were about a similar but totally different problem.
Solution
After trying different things, I tried to ping identity URL from PowerShell
D:\Projects\STB\Source>ping id.stbcom.localhost
Ping request could not find host id.stbcom.localhost. Please check the name and try again.
This gave me a clue that PowerShell is probably not able to resolve the URL so I added a host entry by opening Notepad as an administrator and opening C:\Windows\System32\drivers\etc\host
127.0.0.1 id.stbcom.localhost