ajaxauthenticationproxygraphileon

Graphileon Proxy feature - how to pass credentials


I have one question on the proxy feature of Graphileon. How can we pass credentials like basic auth to Graphileon proxy request hitting a backend API

var body = JSON.stringify({
                    url: "http://localhost:8080/api",
                    method: "POST",
                    body: {key1 : "value1"}
                })

$.ajax({
url: "/proxy",
method: "POST",
data: body
})

Solution

  • You can do it like this:

    var body = JSON.stringify({
                        url: "http://localhost:8080/api",
                        method: "POST",
                        body: {key1 : "value1"},
                        auth: {
                            user: '...',
                            pass: '...',
                            sendImmediately: false | true
                        }
                    })
    

    or

    var body = JSON.stringify({
                        url: "http://<username>:<password>@localhost:8080/api",
                        method: "POST",
                        body: {key1 : "value1"},
               })
    

    or

    var body = JSON.stringify({
                        url: "http://localhost:8080/api",
                        method: "POST",
                        body: {key1 : "value1"},
                        headers: {
                            'Authorization': 'Basic ' + btoa('<username>:<password>')
                        }
        }