Open Closed

如何开放API给第三方系统调用? #9893


User avatar
0
48949912 created

想通过 { "grant_type": "client_credentials", "client_id": "abpdemo_App", "client_secret": "1q11WE" } 这种授权方式,让第三方获取token,需要调用什么接口,系统里有自带的吗?

  • Exception message and full stack trace:
  • Steps to reproduce the issue:
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

7 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • ABP Framework 默认支持 OAuth2 的 client_credentials 授权方式。第三方系统可通过 POST 请求调用 /connect/token 接口获取 token。
    • 请求示例(以 Postman 或代码方式):
    POST https://<your-abp-server>/connect/token
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=client_credentials
    &client_id=abpdemo_App
    &client_secret=1q11WE
    
    • 你需要在 ABP 的 AuthServer 或 IdentityServer 客户端配置中,确保 client_id、client_secret、允许的 grant_type(client_credentials)已正确设置。

    • 系统自带 /connect/token 接口,无需自定义。

    • 参考配置和调用方式详见下方链接。

    Sources:


    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.

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

    可以提供一些参考吗?

    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

    请参考 https://github.com/abpframework/abp/blob/dev/modules/openiddict/app/OpenIddict.Demo.Client.Console/Program.cs#L165-L195

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

    [maliming] said: 请参考 https://github.com/abpframework/abp/blob/dev/modules/openiddict/app/OpenIddict.Demo.Client.Console/Program.cs#L165-L195

    不用这个api吗? POST https://<your-abp-server>/connect/token Content-Type: application/x-www-form-urlencoded

    grant_type=client_credentials &client_id=abpdemo_App &client_secret=1q11WE

    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

    是的, RequestClientCredentialsTokenAsync 也是POST请求

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

    [maliming] said: 是的, RequestClientCredentialsTokenAsync 也是POST请求

    开放给第三方给的话是需要将这个api再封装一下吗,?如:http://serveraddr/RequestClientCredentialsToken

    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

    这个RequestClientCredentialsTokenAsync方法来自 IdentityModel 类库

    https://docs.duendesoftware.com/identityserver/tokens/requesting/#net-client-library

    如果第三方是net 应用程序可以直接引用并使用它获取token并消费API.

    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 September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.