2014-12-05 26 views
1

我目前正在使用免费提供REST网址的Neo4j图形数据库。我试图把它挂到提供双簧管客户端流一个角模块:https://github.com/RonB/angular-oboewithCredentials双簧管要求

我想更好地了解如何添加用户名:在努力抄写本curl命令在我的请求头密码凭据

> curl --user username:password http://localhost:7474/auth/list 

https://github.com/neo4j-contrib/authentication-extension

在角双簧管自述的用法部分,它概述参数对于请求

$scope.myData = Oboe({ 
     url: '/api/myData', 
     pattern: '{index}', 
     pagesize: 100 
    }); 

我有预感添加对withCredentials一个行上的双簧管回购 https://github.com/jimhigson/oboe.js-website/blob/master/content/api.md

双簧管({ URL作为列出:字符串, 方法:字符串; //可选 头:对象,//可选 体:字符串|对象,//可选 缓存:布尔,//可选 withCredentials:布尔//可选,浏览器只 })

但我不知道在哪里把用户名:密码对。

任何帮助你可以提供将非常感谢合作。

回答

1

angular-oboe服务将所有参数传递给Oboe函数,以便您可以指定headers参数。为了确保在请求上允许认证,请指定withCredentials:true。 基本认证可以通过以下方式实现:

.controller('StreamingCtrl', function($scope, Oboe) { 
     $scope.contacts = []; 
     // the contacts streamed 
     $scope.contacts = Oboe({ 
      url: 'http://some.restfull.srv/contacts', 
      pattern: '{contactid}', 
      pagesize: 100, 
      withCredentials: true, 
      headers: { 
       // Base 64 encoded Basis authentication 
       Authorization: 'Basic ' + btoa('username:password') 
      } 
     }); 
    }) 

的BTOA函数将底座64编码的用户名和密码。

编辑: 自从第一个答案以来,angular-oboe工厂发生了变化,并且正在返回promise而不是json对象数组。

这是如何使用最新版本:

angular.module('MyApp') 
    .controller(['$scope', 'Oboe', function($scope, Oboe) { 
     $scope.myData = []; 
     Oboe({ 
      url: '/api/myData', 
      pattern: '{index}', 
      withCredentials: true, 
      headers: { 
       Authentication: 'Basic ' + btoa('yourusername:yourpassword') 
      } 
     }).then(function() { 
      // finished loading 
     }, function(error) { 
      // handle errors 
     }, function(node) { 
      // node received 
      $scope.myData.push(node); 
     }); 
    }]);