Moqui AJAX通话问题

时间:2017-01-24 11:41:37

标签: javascript ajax rest authentication moqui

对本地运行的Moqui的Rest调用存在问题...下面是示例html代码,错误是“REST Access Forbidden(no authz):用户null未授权在REST路径上查看/ moqui /用户”。在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>

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

1 个答案:

答案 0 :(得分:1)

所有工件操作(对于实体,服务,屏幕,REST API等)都需要在Moqui中进行授权。有一些方法可以批量配置它(即继承的authz),但总是会检查每个操作的授权。

以下是一些示例XML,用于授权ADMIN组中所有用户的整个地幔REST API。这也可以在系统应用程序中完成,该应用程序具有用户,用户组,authz等屏幕

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

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