Hi Alexander,

sorry for responding you privately. This was not my intention; I just recognized that my mail program has two reply buttons (replay and reply to mailing list).

I've played a bit around with your code and implemented a small Perl module and a test script. They both work in my environment, however I'm still not happy with them.

What I don't like is...
1st, I need to provide my client version
2nd, I get the message 'truncated' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ) from the user_find API 3rd, I do not know what the id is used for and so I'm unsure if I could automatically handle it in my Perl module

However they should be a help for others who wants use Perl-script to access IPA-API.

Anyway thanks for your help. This was what I need to get on the track.


Am 10.11.2015 um 09:14 schrieb Alexander Bokovoy:
On Mon, 09 Nov 2015, Natxo Asenjo wrote:

On Mon, Nov 9, 2015 at 6:58 PM, Oliver Dörr <oli...@doerr-privat.de> wrote:


I'm completly new to this list and the product behind it. I'm trying to
use perl to get a list from my IPA installation of all users that are on
the server.

unfortunately I cannot help you right now, but have you taken a look at
this blog post:


It could give you some pointers.

Share your code if you get it to work :-)
The code in my response (see other mail) works fine, Oliver contacted me

Oliver, please respond to the list. :)

package freeipa;

use strict;
use REST::Client;
use JSON;
use Data::Dumper;

our $VERSION="0.0.1";


sub new
# Constructor of the class freeipa
{       my ($Class)=@_;
        my $self= {};

        return $self;
}       # sub news

sub set
# Setter of the class freeipa. At this moment only usuable or scalar values 
{       my $ipaObj=shift;
        my $scalar=shift;
        my $value=shift;
}       # sub set

sub connect
# Connects to the specified IPA server
{       my $ipaObj=shift;
        my $headers = {
                'Accept' => 'text/plain',
                'Content-Type' => 'application/x-www-form-urlencoded',
                'Referer' => $ipaObj->{'baseUrl'}
        };      # my $headers
        my $client=REST::Client->new();
        my $params = $client->buildQuery({'user' => $ipaObj->{'user'}, 
'password' => $ipaObj->{'password'} });
        $client->POST("/ipa/session/login_password", substr($params,1), 
        $ipaObj->{'authCookie'} = $client->responseHeader('Set-Cookie');
}       # sub connect

sub ipaMethod
# Calls an API method against the IPA connection
{       my $ipaObj=shift;
        my $hashRef=shift;
        my $data = {
                'params' => [
                                                { 'version' => 
$ipaObj->{'version'} }
        };      # my $data
        my $headers = {
                'Accept' => 'text/plain',
                'Content-Type' => 'application/json',
                'Cookie' => $ipaObj->{'authCookie'},
                'Referer' => $ipaObj->{'baseUrl'}."/ipa/session/json"
        # Copy the specified part of the method over the default data defined 
in $data
        foreach my $var (keys (%{$hashRef})) { $data->{$var}=$hashRef->{$var}; }
        # Format the method and data to json and make a REST request against 
the IPA server
        my $jsonMethod = to_json($data);
        $ipaObj->{'restClient'}->POST("/ipa/session/json", $jsonMethod, 
        # bring the JSON-formed response into perl objects...
        my $restRet=from_json($ipaObj->{'restClient'}->responseContent());
        # ... and return ist
        return $restRet;
}       # sub ipaMethod

Attachment: testConnection.pl
Description: Perl program

Manage your subscription for the Freeipa-users mailing list:
Go to http://freeipa.org for more info on the project

Reply via email to