Open Closed

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. #9993


User avatar
0
cetin.sahin created

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)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent

    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:

    1. 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 as ReactAppService, email, profile, etc.).
      • The client (React_Client) must be allowed to request the API resource's scope.
    2. 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.
    3. API Host Configuration:

      • In the API Host's appsettings.json, set the AuthServer: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).
    4. 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.
    5. Token Usage:

      • When calling the API Host, use the access token obtained from the Auth Server in the Authorization: Bearer header.

    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:

    1. Register API Resource in Auth Server:
    "ApiResources": {
         "ReactAppService": {
           "Scopes": [ "ReactAppService" ]
         }
       }
    
    1. Register Scope for Client:
    "Clients": {
         "React_Client": {
           "Scopes": [ "ReactAppService", "email", "profile", "offline_access" ]
         }
       }
    
    1. Configure API Host:
    "AuthServer": {
         "Authority": "https://localhost:44387",
         "RequireHttpsMetadata": true,
         "ApiName": "ReactAppService"
       }
    
    1. Request Token with Correct Scope:
    POST /connect/token
       client_id=React_Client
       client_secret=1q2w3E*
       grant_type=client_credentials
       scope=ReactAppService offline_access
    
    1. 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.

  • User Avatar
    0
    cetin.sahin created

    this error stil get

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on October 14, 2025, 08:24