Problems with jaydata basic authentication

允我心安 提交于 2019-12-13 05:30:38

问题


Jaydata & Javascript noobie. I'm having problems with jaydata and basic authentication, can't seem to get it to work. I specify user and password but the headers never contains an auth line. Jaydata version is 1.3.6

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="/scripts/jquery-1.11.0.js"></script>
    <script type="text/javascript" src="/scripts/datajs-1.0.3.js"></script>
    <script type="text/javascript" src="/scripts/jaydata.js"></script>
    <script type="text/javascript" src="/scripts/jaydataproviders/oDataProvider.js"></script>
    <script type="text/javascript" src="/scripts/zawtst.js"></script>
    <script>
        var nwcontext = new ZAWTST_SRV.ZAWTST_SRV({
            name: 'oData',
            oDataServiceHost: 'http://vmerpd01.sap.int:8080/sap/opu/odata/sap/zawtst_srv',
            user: "XXXXX",
            password: "xxxxxxx"
        });

        function createItemLI(name, id, css) {
            var li = $('<li></li>').append(name).addClass(css).data('id', id);
            return li;
        }

        $(function () {
            nwcontext.SalesOrderCollection.toArray(function (SalesOrderCollection) {
                SalesOrderCollection.forEach(function (category) {
                    $('#categories').append(
                        createItemLI(SalesOrder.SdDoc, SalesOrder.Material, 'category'));
                });
            });
        });
    </script>
</head>
<body>
    <ul id="categories">
    </ul>
</body>

When testing in Chrome, I see no auth line:

Remote Address:10.1.8.171:8080
Request URL:http://vmerpd01.sap.int:8080/sap/opu/odata/sap/zawtst_srv/SalesOrderCollection
Request Method:OPTIONS
Status Code:401 Unauthorized
Request Headers -----------------------
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, maxdataserviceversion, dataserviceversion, authorization
Access-Control-Request-Method:GET
Cache-Control:max-age=0
Connection:keep-alive
Host:vmerpd01.sap.int:8080
Origin:http://10.8.0.6:8080
Referer:http://10.8.0.6:8080/index.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Response Headers --------------------
content-encoding:gzip
content-length:947
content-type:text/html; charset=utf-8
sap-system:GD1
www-authenticate:Basic realm="SAP NetWeaver Application Server [GD1/400]"

Yet here in the javascript console I can see the auth line.

Exception {name: "HTTP request failed", message: "", data: Arguments[1], stack: (...), _getStackTrace: function}
data: Arguments[1]
0: Object
message: "HTTP request failed"
request: Object
callbackParameterName: "$callback"
data: undefined
enableJsonpCallback: false
formatQueryString: "$format=json"
headers: Object
Accept: "application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1"
Authorization: "Basic WFhYWFg6eHh4eHh4eA=="
DataServiceVersion: "2.0"
MaxDataServiceVersion: "2.0"
__proto__: Object

Any thoughts ?


回答1:


Use the $data.Authentication.BasicAuth API to login:

httpAuth = new $data.Authentication.BasicAuth.BasicAuth({
    username: "XXXXX",
    password: "xxxxxxx"
    });

context.storageProvider.AuthenticationProvider = httpAuth.CreateRequest({});

httpAuth.Login({
    success: function (data) { }
              });

References

  • JayData API
  • Facebook friend list example


来源:https://stackoverflow.com/questions/23097457/problems-with-jaydata-basic-authentication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!