-
Notifications
You must be signed in to change notification settings - Fork 10.3k
unauthorized_client error on Login
CONTENT
This error occurs because the connecting app (the "Client") isn't registered in the IdentityServer database as an authorized client.
The authorized client registration occurs when the Identity DB is seeded, and in eShopOnContainers this happens when the DB is first created. So this only happens when first installed or when restarting the Identity service if the DB has been deleted.
When registering the clients, eShopOnContainers reads the values from the following configuration variables, from either the appsettings.json
file, the docker-compose.override.yml
file or the equivalent environment variables:
- SpaClient
- MvcClient
- LocationApiClient
- MarketingApiClient
- BasketApiClient
- OrderingApiClient
- MobileShoppingAggClient
- WebShoppingAggClient
- WebhooksApiClient
- WebhooksWebClient
Docker removed DockerNAT in Docker Desktop Community 2.2 so you can't use localhost
to access a container and you must switch to host.docker.internal
This can be the result of any, or a combination, of the two causes above.
IdentityServer uses the RedirectUri
to decide if the connecting client is authorized
When a user that's not been authorized tries to use the [client] app, they are redirected to the IdentityServer's /connect/authorize
endpoint, and the request includes a redirection uri that's used to complete the login process, as shown in the following image:
The authorized clients are registered in the Clients
table and the related redirect URIs in the ClientRedirectUris
table as shown in the following image:
It's important to keep in mind that if the application is registered as http://host.docker.internal:5004
but started as http://localhost:5104
it's considered to be a different one, so it'll get the unauthorized_client
message.
The startup address is defined in the .env
file and used in docker-compose.override.yml
as shown in the following images.
.env file
cocker-compose.override.yml file
IMPORTANT
You MUST run the docker-compose up command from the folder where the .env file is, otherwise the values defined in the file won't be used.
So the possible solution could be one or a combination of:
-
Make sure you are starting the app from the correct address.
-
Update the
.env
file as needed. -
Update the
ClientRedirectUris
table to the correct values. -
Drop the
IdentityDb
database and restart theIdentity
service, after updating thedocker-compose.override.yml
file, or theconfigmap.yaml
in Kubernetes, so that all the clients are registered correctly.
- System requirements
- Development setup
- Databases & containers
- Architecture
- Application
- Code
- Logging and Monitoring
- Tests