-
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 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
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.
So the possible solution are:
-
Make sure you are starting the app from the correct address.
-
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