Moqui AJAX通话问题


                    

在本地运行的Moqui的Rest调用存在问题...以下是示例html代码,错误为“禁止REST访问(无身份验证):未授权用户null用于REST路径/ moqui /上的视图 用户”。 在Web控制台上,错误是403(禁止访问)。</ p>

  <!DOCTYPE html>

<头>

AJAX测试</ title>
&lt;/ script&gt;<br> &lt;/ head&gt;</p> <p>&lt;身体&gt;</p> <p>&lt;脚本&gt;</p> <p>$(document).ready(function(){<br> $ .ajax({<br> 类型:“ GET”,<br> 网址:“ http:// localhost:8080 / rest / s1 / moqui / users”,<br> 标头:{</p> <p>             接受:“ application / json”,<br>              授权:“基本am9obi5kb2U6bW9xdWk =“<br>          },</p> <p>     contentType:“应用程序/ json”<br>      })。then(function(data){<br>      console.log(data);<br> });<br> });</p> <p>&lt;/ script&gt;<br> &lt;/ body&gt;<br> &lt;/ html&gt;<br> &lt;/ code&gt; &lt;/ pre&gt;</p> <p><p> <a href="https://i.stack.imgur.com/rDddy.png" rel="nofollow noreferrer"> <img src =“ https://i.stack.imgur.com/rDddy。 png“ alt =” Api调用在Chrome Rest Client上可以正常使用,但在AJAX调用上无法使用“> </a> &lt;/ p&gt;<br>      &lt;/ div&gt;</p>

展开原文

原文

There is an issue with the Rest call to Moqui running locally... Below is the sample html code and the error is "REST Access Forbidden (no authz): User null is not authorized for View on REST Path /moqui/users". And on the web console the error is 403 (Forbidden).

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AJAX Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>

<body>

<script>

$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:8080/rest/s1/moqui/users",
headers: {  

            Accept: "application/json",
            Authorization : "Basic am9obi5kb2U6bW9xdWk="
        },

    contentType: "application/json"
    }).then(function(data) {
    console.log(data);
});
});

</script>
</body>
</html>

Api call works fine when tried with a Chrome Rest Client, but not with AJAX call

1个回答


所有工件操作(用于实体,服务,屏幕,REST API等)都需要Moqui中的授权。 有许多方法可以批量配置(即继承的authz),但始终会检查每个操作的授权。</ p>

以下是一些XML示例示例,用于授权ADMIN组中的所有用户使用完整的REST API。 这也可以在“系统”应用程序中完成,该应用程序具有用于用户,用户组,身份验证等的屏幕。</ p>

  <!-通过mantle资源(根资源)用于所有Mantle REST API的工件组->

    
    
</ artifactGroups>
</ code> </ pre>

“使用Moqui制作应用程序”一书中有关于“工件授权”功能的更多常规文档(您可以在moqui.org上下载PDF)。 尽管REST API功能比本书更新,因此尚未涵盖,但与屏幕授权相同的模式适用于REST API。</ p>
     </ div>

展开原文

原文

All artifact operations (for entities, services, screens, REST API, etc) require authorization in Moqui. There are ways to configure this in bulk (ie inherited authz) but authorization is always checked for every operation.

Here is some example XML for authorization to the entire mantle REST API for all users in the ADMIN group. This can also be done in the System application which has screens for users, user groups, authz, etc.

<!-- Artifact group for all of the Mantle REST API via the mantle resource (the root resource) -->
<artifactGroups artifactGroupId="MANTLE_API" description="Mantle REST API (via root resource)">
    <artifacts artifactTypeEnumId="AT_REST_PATH" artifactName="/mantle" inheritAuthz="Y"/>
    <authz artifactAuthzId="MANTLE_API_ADMIN" userGroupId="ADMIN" authzTypeEnumId="AUTHZT_ALWAYS" authzActionEnumId="AUTHZA_ALL"/>
</artifactGroups>

There is more general documentation on the Artifact Authorization functionality in the Making Apps with Moqui book (you can download the PDF on moqui.org). Even though the REST API functionality is more recent than the book and so not yet covered in it, the same pattern as for screen authorization applies to the REST API.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问