Oauth 2.0 Ajex无需登录Active Directory即可访问Protect API

Oauth 2.0 Ajex无需登录Active Directory即可访问Protect API,oauth-2.0,azure-api-management,Oauth 2.0,Azure Api Management,我遵循这个示例,在设置>用户授权下选择了EchoAPI的OAuth 2.0 然后,我用https://{myapi}.azure API.net/Echo/resource cached?param1=sample创建了一个html文件,并触发了对Echo API https://{myapi}.azure API.net/Echo/resource cached的ajax调用 我假设我应该收到一个错误,比如访问被拒绝或没有授权,因为这个API应该由我的OAuth服务器保护。根据示例,它是我的A

我遵循这个示例,在设置>用户授权下选择了EchoAPI的OAuth 2.0

然后,我用https://{myapi}.azure API.net/Echo/resource cached?param1=sample创建了一个html文件,并触发了对Echo API https://{myapi}.azure API.net/Echo/resource cached的ajax调用

我假设我应该收到一个错误,比如访问被拒绝或没有授权,因为这个API应该由我的OAuth服务器保护。根据示例,它是我的AD。但是,这个ajax调用返回状态代码:200。我不需要登录我的广告,但可以使用API

   $(document).ready(function(){
      $("button").click(function(){
        $.ajax({
             url: "https://{myapi}.azure-api.net/echo/resource?param1=sample"
            ,headers: {
                'Cache-Control':'no-cache',
                'Ocp-Apim-Trace':'true',
                'Ocp-Apim-Subscription-Key':'xxxxxxxxxxxxxxxxxxxxxx'
            }
            ,success: function(result){
                $("#div1").html(JSON.stringify(result));
                }
            ,error : function(result) {
                alert(JSON.stringify(result));
            }
        });

      });
    });
我用模拟响应手动创建了另一个名为demo的API。此API返回一个json{'sampleField':'test'}。我的Ajex调用接收json而不使用ISU,即使我在该API中应用了OAuth 2.0作为用户授权


是否有什么我遗漏或误解了它的工作原理?

最后,JWT需要阻止它

将OAuth/OIDC服务器分配给API纯粹是一种文档姿态。此信息在测试控制台的dev portal中使用,以便人们可以轻松获得令牌来调用您的API,但强制执行仍应由后端处理。您是正确的,要强制请求具有特定标识,应该使用validate jwt策略。