Basic Auth

From DreamFactory
Jump to: navigation, search
      1. Tutorial

DreamFactory 2.0 supports Basic HTTP Authentication both via Authorization request header and URL.

      1. API Endpoints
        1. Using Authorization request header
{METHOD} https://{url}/api/v2/{service}/{resource}

Request Header:

 Accept-Encoding:gzip, deflate, sdch
 Authorization:Basic {base64_encode(username + : + password)}    <-- Basic Authentication
        1. Using URL
{METHOD} https://username:[email protected]{url}/api/v2/{service}/{resource}

> _Note: Basic Authentication over URL will not work for user agents that support request header (most web browsers)_

      1. Example - Basic Authentication via Authorization request header using JQuery Ajax call
var username = $('#username').val();
var password = $('#password').val();
var url = $('#url').val();
    url: url,
    async: true,
    dataType: 'json',
    contentType: 'application/json',
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", "Basic "+btoa(username+':'+password));
    success: function(json){
    error: function(err) {
      1. Example - Basic Authentication via URL using CURL
curl http://username:[email protected]/rest/system/service