简体   繁体   English

如何授权Webapi端点供第三方使用

[英]How to authorize webapi endpoint for 3rd party to use

I have to create a endpoint that will use used by a 3rd party. 我必须创建一个将由第三方使用的端点。 We use identity server when people log in to our application. 当人们登录到我们的应用程序时,我们将使用身份服务器。 What do I need to do to only allow access to this 3rd party to call the endpoint? 我只需要允许访问此第三方来呼叫端点,该怎么办? I dont want just anyone to be able to call the endpoint. 我不希望任何人都能呼叫端点。 For example, if I gave you my endpoint URL and you used postman to post to it, I would only allow you if you were authorised 例如,如果我给您我的终结点URL,并且您使用邮递员将其发布到该URL,则只有在您被授权的情况下,我才允许您

I think you need to enable CORS (Cross-Origin Requests) as outlined by Microsoft here . 我认为您需要启用Microsoft在此概述的 CORS(跨域请求)。

For example, you would decorate your controller as so: 例如,您可以这样装饰控制器:

using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Cors;

namespace WebService.Controllers
{
    [EnableCors(origins: "http://mywebclient.azurewebsites.net", headers: "*", methods: "*")]
    public class TestController : ApiController
    {
        // Controller methods not shown...
    }
}

There are a number of ways to secure an ASP.NET web app/api. 有多种方法可以保护ASP.NET Web应用程序/ api。

I typically use a SQL user store or active directory and issue JWT tokens. 我通常使用SQL用户存储或活动目录并发出JWT令牌。 A nice guide can be found here. 一个很好的指南可以在这里找到。

https://jonhilton.net/2017/10/11/secure-your-asp.net-core-2.0-api-part-1---issuing-a-jwt/ https://jonhilton.net/2017/10/11/secure-your-asp.net-core-2.0-api-part-1---issuing-a-jwt/

Here is the documentation for identity server - as you mentioned you wanted to use that - about this very topic. 这是身份服务器的文档-正如您提到的那样,您想使用它-有关此主题的文档。

http://docs.identityserver.io/en/release/topics/apis.html http://docs.identityserver.io/en/release/topics/apis.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 DNX-如何使用第三方库调试符号? - DNX - how to use 3rd party library debugging symbols? 如何在Azure云服务上使用第三方DLL - How to use 3rd party DLL on Azure Cloud Service 我们如何使用第三方API为Webapi创建单元测试 - How Can We Create Unit Tests For Webapi With 3rd Party API's 如何禁用第三方事件循环 - How to disable 3rd party event loop 如何序列化第三方课程? - How to serialize 3rd party class? 如何在第三方ASP.NET Web API客户端中使用Oauth生成的令牌? - How to use an Oauth Generated Token in a 3rd party asp.net web API client? 如何在Windows Phone中在没有任何第三方库的情况下使用具有OAuth身份验证的Twitter REST API 1.1 - How to use Twitter REST API 1.1 with OAuth Authentication without any 3rd party libraries in Windows Phone C#Express:如何发布要与第三方安装程序(msi)一起使用的项目? - C# Express: How to publish project for use with 3rd party installer (msi)? 如何在我的解决方案中强制使用第三方dll来使用更新版本的另一个dll? - How can I enforce a 3rd party dll to use a newer version of another dll in my solution? 如何在Windows Phone 8(WP8)上使用外部或第三方字体? - How to use external or 3rd party fonts on Windows Phone 8 (WP8)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM