API Authentication

From Wiki

Jump to: navigation, search


Contents

Basics

In all examples bellow, the username used is admin and the password used is lalala.

In all examples bellow we assume that the URL on which you will access the local interface is:

http://IP-of-the-server/~1h/local-interface/

And portal:

http://IP-of-the-server/~1h/portal/

All data returned from the API calls is JSON encoded. For more information about parsing JSON encoded data look at this page

Skip authentication from a certain IP

In /home/1h/public_html/ you can put an .htaccess file with the following content:

SetEnvIf Remote_Addr 14.15.16.2 master
SetEnvIf Remote_Addr 15.16.17.3 master
AuthType Basic
AuthName "1H Systems for authorized users only."
AuthUserFile "/home/1h/etc/web.passwd"
require valid-user
order deny,allow
deny from all
allow from env=master
Satisfy any

So the IPs 14.15.16.2 and 15.16.17.3 will skip the authentication and will be allowed to directly connect to the application.

You can still use Apache Basic Authentication to connect to the APIs, but if you want easier access, we provide you with this solution.

Authentication with Bash

curl --basic -u admin:lalala http://IP-of-the-server/~1h/local-interface/

Authentication with Perl

#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
$browser->credentials(
  'IP-of-the-server:80',
  'admin' => 'lalala'
);

my $req = GET 'http://IP-of-the-server/~1h/local-interface/';
$req->authorization_basic('admin', 'lalala');

my $content = $browser->request($req)->as_string;
print "Content is $content"; 

Authentication with PHP

 <?php
 $host = 'http://IP-of-the-server/~1h/local-interface/';
 $username = 'admin';
 $password = 'lalala';
 $process = curl_init($host);   
 curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);   
 $return = curl_exec($process); 
 echo($return);
?>

Authentication with Python

import urllib2

theurl = 'http://IP-of-the-server/~1h/local-interface/'
username = 'admin'
password = 'lalala'

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, theurl, username, password) 
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler) 
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(theurl)
print pagehandle.read();

Future

In the future we will offer OpenID and other stronger methods of authentication.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox