Open Closed

How can I call the API from a simple console .NET Core application or from postman? #314


User avatar
0
camping89@gmail.com created
  • ABP Framework version: v3.0.3
  • UI type: MVC
  • Tiered (MVC) or Identity Server Seperated (Angular): yes

How can I call the API from a simple console .NET Core application or from postman? Assuming that we are trying to use the HttpApi from an independent console app which lately will be used to create as a background service.

Here are the very basic things but I can't find enough document to do the training

  • How to get access token from an API call (because the console app will be triggered by something else, not by human, this should be an API call)
  • Calling the API as anonymous user
  • Calling the API with authenticated user (using username/password OR using the access token)

Another thing is using POSTMAN to test the HttpAPI. This should work as the same way as above concerns but in POSTMAN.


3 Answer(s)
  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    • Console application You can check the console application : https://github.com/abpframework/abp/blob/dev/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs.
    • Postman You can call token endpoint to get access token, See : https://identityserver4.readthedocs.io/en/latest/endpoints/token.html
  • User Avatar
    0
    camping89@gmail.com created

    Hi @liangshiwei

    Firstly, thanks a lot for your help. I didn't see such example in the generated project from ABP. The one created is much simpler (without the test methods). So to continue with it, here are something I'm not sure

    1. Where can I find sample app service and the configuration impl?
    2. Talking about API Resource and the Scope, by default there is a <ProjectName> scope in the API resource, in which file/where does ABP Identity enforce the authorization for this scope for all APIs? Sth like this

    (Note that the appsettings.json is populated already)

    Also, can you help to send/point out some documentation related to scope and the configuration with API in ABP? I need this for some trainings.

    Thanks,

  • User Avatar
    1
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    1. You can use the CLI to create a module project and you will see the console application in the aspnet-core/test folder. It just a simple application.
    2. Abp used oauth2.0 protocol for authorization, see https://github.com/abpframework/abp/blob/d4551c83b7379b8a47e82bbe3adfbcf02273e54a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs#L96

    There are some document:

    Authorization OAuth2.0 IdentityServer4 abp commercial IdentityServer4

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