We would like to use a central ABP.io Auth Server and configure another project's API Host to obtain tokens from this central Auth Server.
For this purpose, we created two separate solutions: SSO and ReactAppService. We added the application to the Auth Server as React_Client. We configured the ReactAppService project's API Host to use the Auth Server in the SSO solution.
However, when we try to get a token via Postman and call the /api/identity/users POST method, we receive an authorization error.
React client Host api appseting
Token postman
create abp user sample
2 Answer(s)
-
0
To use a central ABP Auth Server and have another project's API Host accept tokens from this Auth Server, you must ensure the following key points are correctly configured:
API Resource Registration in Auth Server:
- The API Host (ReactAppService) must be registered as an API resource in your central Auth Server (SSO).
- In the Auth Server, add a new API resource (e.g.,
ReactAppService
) and include the required scopes (such asReactAppService
,email
,profile
, etc.). - The client (React_Client) must be allowed to request the API resource's scope.
Scope Usage in Token Request:
- When requesting a token, the
scope
parameter must include the API resource scope (e.g.,scope=ReactAppService offline_access
), not just the client or SSO scope. - If you only request
MerkeziSSO offline_access
, the access token may not be valid for the API Host.
- When requesting a token, the
API Host Configuration:
- In the API Host's
appsettings.json
, set theAuthServer:Authority
to the central Auth Server's URL. - Ensure the
AuthServer:RequireHttpsMetadata
is set according to your environment. - The API Host must be configured to validate tokens issued by the central Auth Server and recognize the correct audience (API resource).
- In the API Host's
Audience Validation:
- The API Host must validate the
aud
(audience) claim in the JWT. This must match the API resource name you registered in the Auth Server. - If the audience does not match, you will get a 401 Unauthorized error.
- The API Host must validate the
Token Usage:
- When calling the API Host, use the access token obtained from the Auth Server in the
Authorization: Bearer
header.
- When calling the API Host, use the access token obtained from the Auth Server in the
Common Issues and Solutions:
- 401 Unauthorized: Usually caused by missing or incorrect audience in the token, or the API Host not configured to accept the token from the central Auth Server.
- Missing API Resource: Ensure the API Host is registered as an API resource in the Auth Server and the client is allowed to request its scope.
Example Steps:
- Register API Resource in Auth Server:
"ApiResources": { "ReactAppService": { "Scopes": [ "ReactAppService" ] } }
- Register Scope for Client:
"Clients": { "React_Client": { "Scopes": [ "ReactAppService", "email", "profile", "offline_access" ] } }
- Configure API Host:
"AuthServer": { "Authority": "https://localhost:44387", "RequireHttpsMetadata": true, "ApiName": "ReactAppService" }
- Request Token with Correct Scope:
POST /connect/token client_id=React_Client client_secret=1q2w3E* grant_type=client_credentials scope=ReactAppService offline_access
- Call API with Token:
Authorization: Bearer {access_token}
Summary Checklist:
- [ ] API Host is registered as an API resource in Auth Server.
- [ ] Client is allowed to request the API Host's scope.
- [ ] Token request includes the correct API resource scope.
- [ ] API Host is configured to validate tokens from the central Auth Server and checks the correct audience.
- [ ] Access token is sent in the Authorization header when calling the API.
If you follow these steps and ensure the scopes and audiences are correct, your API Host should accept tokens from the central Auth Server.
No verified source available for this specific query.
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
this error stil get