Open Closed

How can I call an ABP remote service method? #560


User avatar
0
alper created
Support Team Director

I want to login to my ABP project and execute an authenticated Rest API action with the token.

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    In your solution directory, there's a folder called test. In the test folder, you'll find *.HttpApi.Client.ConsoleTestApp project. This project is a sample console application that logins to the backend and makes an authenticated API call. To be able to run this project, run the following projects

    • *.HttpApi.Host
    • *.IdentityServer

    Configure your host credentials in the appsettings.json of this console application:

    Run in debug, to make a request for fetching all users. (it's an authenticated request and adds bearer token automatically)

    If you want to manually build your own API client you can follow the IDS4 documentation: https://identityserver4.readthedocs.io/en/latest/quickstarts/1_client_credentials.html#creating-the-client


    On the other hand, you can also check out the ABP CLI code as an example. It authenticates to the backend and make API calls.

    1. Login => https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/LoginCommand.cs#L51
    2. Set Bearer token => https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Http/CliHttpClient.cs#L48
    3. Make a remote service all => https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpNuGetIndexUrlService.cs#L22
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    shobhit created

    Hello Alper, Thanks but as i am new in ABP and Identity so i am confused. I am providing basic details: 1- Login using microsoft authtentication as per screen shot:

           2- Received auth token in angular UI           
           3- Call ABP custom api (workflowAPI to give the name)
           4- Pass auth token to calling api in header as "Authorization"
           5- Get the auth token in ABP workflowAPI api as below code:
       
    
        
               Declare in class:
               private readonly IHttpContextAccessor _httpContextAccessor;
               
               Within Method:
               var accessToken = _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
               
                var client = new RestClient(url);           
                client.AddDefaultHeader("Authorization", accessToken);
                client.AddDefaultHeader("Content-Type", "application/json");
                client.AddDefaultHeader("Accept", "application/json");
                
                RestRequest restRequest = new RestRequest();
    
                var response = client.Execute<T>(restRequest);
                
    
            Error:
            "Unauthorized"
            
            Reason:
            "accessToken" is an  ABP identity server auth token not the Microsoft access token.
            
            
            Help Required:
            How to get the microsoft access token in my method. Can you give me step by step details.
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi @shobhit

    Is your purpose to log in through Microsoft or other social accounts in Angular?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    shobhit created

    Hi Maliming, Ok. Scenario is: 1- User login using microsoft account (Done) 2- User view menu (Done) as per permission 3- User have one menu option "Workflow service". 4- User clicks the "workflow service" menu 5- Backend API "WorkflowserviceList" get triggered 6- Within "WorkflowserviceList" a microsoft api i.e. (GetWorkflowInstances) is called 7- To call microsoft api "GetWorkflowInstances", caller should pass microsoft access token

                  ABP API: 
                  
                  Public WorkflowserviceList()
                  {
                             Call microsoft API GetWorkflowInstances(Access Token);                             
                  }
                  
                  Access token should be of the same user who has logged in.
                  
                  I hope i am clear now.
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    -1
    maliming created
    Support Team Fullstack Developer

    We can't provide much help on the question of calling Microsoft APIs. I recommend that you check Microsoft's document. : )

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
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.8.0-preview. Updated on October 05, 2026, 11:32
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.