Starts in:
1 DAY
8 HRS
8 MIN
1 SEC
Starts in:
1 D
8 H
8 M
1 S
Open Closed

How do I communicate between two APIs? #6076


User avatar
0
yunusemrecaglar created
  • ABP Framework version: v7.2.2
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes

https://support.abp.io/QA/Questions/5792/Token-Create Hello,

In the previous link, I asked how to make requests from Project A's frontend to Project B's API through a shared authentication server. Now, I'd like to know how to make requests from the backend of Project A to the backend of Project B.


9 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi

    Please read this by doing this you can communicate between project using client_credentials

    https://docs.abp.io/en/commercial/latest/startup-templates/microservice/synchronous-interservice-communication

    https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow

  • User Avatar
    0
    yunusemrecaglar created

    Hi, Both projects are monolithic projects, how can I make them work with a single token?

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi

    using client_credentials please check how to create client_credentials client in the project that want it to be accessed and make a http call https://support.abp.io/QA/Questions/5943/Modify-tenant-onboard-flow-by-customizing-tenant-management-module-UI-and-API#answer-3a0e2ff0-2171-cf2a-60f2-c4164551b1cf

    use of client credentials and assigning them permission

    you can you http client to make call to another app service.

    This is nothing to do with monolith or any other project type these are just communication form server to server using client_credentials grant type

  • User Avatar
    0
    yunusemrecaglar created

    Hi, I can perform the actions highlighted in green. What I want to do is what's marked in red. I cannot perform the action marked in red. With this code: 'await HttpClientAuthenticator.Authenticate(new RemoteServiceHttpClientAuthenticateContext(client, requestMessage, new RemoteServiceConfiguration(baseUrl), string.Empty));' I can make a request from Project B's frontend to the API in Project A. However, I cannot use this code in Project B's API, so I cannot obtain the token. Therefore, when I go from Project B's API to Project A's API, it returns a 401 error. How can I obtain the token of a user who has logged in to Project B's API? If I obtain the token, I can make requests to Project A's API using that token.

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi

    Create a Client in Project A of client credentials by providing the sufficient permission of project a api permissions then from project b get the token

    you can see how to get token https://support.abp.io/QA/Questions/5943/Modify-tenant-onboard-flow-by-customizing-tenant-management-module-UI-and-API#answer-3a0e2ff0-2171-cf2a-60f2-c4164551b1cf

    make sure to use project a auth server url to get the token and then use that token to call the project a api.

  • User Avatar
    0
    yunusemrecaglar created

    hi, I don't understand how to obtain the token of a user who has logged in the 'ProjectB.Application' project.

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi

    it is not a user's token as it is a server to server communication it can't be a user token https://oauth.net/2/grant-types/client-credentials/ please read more about client credentials flow

  • User Avatar
    0
    yunusemrecaglar created

    ! image.png

    How can I find current user token?

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi

    When you send a request to backend through the angular, angular app sends the access token in the Request so the access token should be in the httpcontext request

    please read more here https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.authenticationtokenextensions.gettokenasync?view=aspnetcore-7.0

    HttpContext.Request.GetTokenAsync("access_token")

    or HttpContext.GetTokenAsync("access_token")

    you can do these in the controller

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06