简体   繁体   English

Moqui AJAX通话问题

[英]Moqui AJAX call issue

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". 在本地运行的对Moqui的Rest调用存在问题……下面是示例html代码,错误为“禁止REST访问(无身份验证):未授权用户null用于在REST Path / moqui / users上查看”。 And on the web console the error is 403 (Forbidden). 并且在Web控制台上,错误为403(禁止)。

<!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>

尝试与Chrome Rest Client一起使用时,Api调用工作正常,但与AJAX调用不兼容

All artifact operations (for entities, services, screens, REST API, etc) require authorization in Moqui. 所有工件操作(针对实体,服务,屏幕,REST API等)都需要在Moqui中进行授权。 There are ways to configure this in bulk (ie inherited authz) but authorization is always checked for every operation. 有许多方法可以批量配置(即继承的authz),但始终会检查每个操作的授权。

Here is some example XML for authorization to the entire mantle REST API for all users in the ADMIN group. 这是一些XML示例,用于授权ADMIN组中的所有用户使用完整的REST API。 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). 在使用Moqui制作应用程序一书中,有更多关于Artifact授权功能的常规文档(您可以在moqui.org上下载PDF)。 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. 尽管REST API功能比本书更新,因此尚未涵盖,但与屏幕授权相同的模式也适用于REST API。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM