angularjs - withCredentials oboe request -


i working neo4j graph database offers rest url's free. , trying hook angular module provides oboe client side streaming: https://github.com/ronb/angular-oboe

i trying better understand how add username:password credentials in request header in effort transcribe curl command

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

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

in usage section of angular-oboe readme, outlines parameters request

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

i have hunch add line withcredentials listed on oboe repo https://github.com/jimhigson/oboe.js-website/blob/master/content/api.md

oboe({ url: string, method: string, // optional headers: object, // optional body: string|object, // optional cached: boolean, // optional withcredentials: boolean // optional, browser })

but i'm not sure put username:password pair.

any offer appreciated in collaboration.

the angular-oboe service passes parameters oboe function can specify headers parameter. make sure authentication allowed on request specify withcredentials: true. basic authentication can achieved by:

    .controller('streamingctrl', function($scope, oboe) {         $scope.contacts = [];         // 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')             }         });     }) 

the btoa function base 64 encode username , password.

edit: angular-oboe factory has been altered since first answer , returning promise instead of array of json objects.

this how use latest version:

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);         });     }]); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -