Re: [Freeipa-users] First tests against the REST/JSON API

2015-11-10 Thread Oliver Dörr

Hello,

just because I could answer my 2nd problem by myself. The truncated does 
not come from user_find API. It came from the perl JSON module, this is 
using this to write boolean variables. There is a special handling for 
boolean values inside this module which I have to implement.


Regards
Oliver

Am 10.11.2015 um 15:53 schrieb Oliver Dörr:

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.

Oliver

Am 10.11.2015 um 09:14 schrieb Alexander Bokovoy:

On Mon, 09 Nov 2015, Natxo Asenjo wrote:

hi,

On Mon, Nov 9, 2015 at 6:58 PM, Oliver Dörr  
wrote:



Hi,

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:

https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/ 



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
privately.

Oliver, please respond to the list. :)






-- 
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project

Re: [Freeipa-users] First tests against the REST/JSON API

2015-11-10 Thread Oliver Dörr

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.

Oliver

Am 10.11.2015 um 09:14 schrieb Alexander Bokovoy:

On Mon, 09 Nov 2015, Natxo Asenjo wrote:

hi,

On Mon, Nov 9, 2015 at 6:58 PM, Oliver Dörr  
wrote:



Hi,

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:

https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/

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
privately.

Oliver, please respond to the list. :)


package freeipa;

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

our $VERSION="0.0.1";


BEGIN {
};


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

bless($self,$Class);
$self->{'id'}=0;
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;

$ipaObj->{$scalar}=$value;
}   # 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->setHost($ipaObj->{'baseUrl'});
$client->POST("/ipa/session/login_password", substr($params,1), 
$headers);
$ipaObj->{'authCookie'} = $client->responseHeader('Set-Cookie');
$ipaObj->{'restClient'}=$client;
}   # sub connect


sub ipaMethod
# Calls an API method against the IPA connection
{   my $ipaObj=shift;
my $hashRef=shift;
my $data = {
'id'=>$ipaObj->{'id'},
'params' => [
[],
{ 'version' => 
$ipaObj->{'version'} }
]
};  # my $data
$ipaObj->{'id'}++;

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, 
$headers);

# bring the JSON-formed response into perl objects...
my $restRet=from_json($ipaObj->{'restClient'}->responseContent());

# ... and return ist
return $restRet;
}   # sub ipaMethod

testConnection.pl
Description: Perl program
-- 
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project

Re: [Freeipa-users] First tests against the REST/JSON API

2015-11-10 Thread Alexander Bokovoy

On Mon, 09 Nov 2015, Natxo Asenjo wrote:

hi,

On Mon, Nov 9, 2015 at 6:58 PM, Oliver Dörr  wrote:


Hi,

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:

https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/

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
privately.

Oliver, please respond to the list. :)
--
/ Alexander Bokovoy

--
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project


Re: [Freeipa-users] First tests against the REST/JSON API

2015-11-09 Thread Natxo Asenjo
hi,

On Mon, Nov 9, 2015 at 6:58 PM, Oliver Dörr  wrote:

> Hi,
>
> 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:

https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/

It could give you some pointers.

Share your code if you get it to work :-)

Thanks.

--
regards,
natxo
-- 
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project

Re: [Freeipa-users] First tests against the REST/JSON API

2015-11-09 Thread Alexander Bokovoy

On Mon, 09 Nov 2015, Oliver Dörr wrote:

Hi,

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.




#!/usr/bin/perl

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

my $username="admin";
my $password="secret";
my $headers= {
   'Accept' => 'application/json',
   'Content-Type' => 'application/x-www-form-urlencoded',
   'Authorization' => 'Basic',
   'user' => encode_base64($username),
   'password' => encode_base64($password)
   #encode_base64($username.":".$password)
};

my $client=REST::Client->new();
$client->setHost("https://ipa.kreditwerk.de";);
$client->POST("/ipa/session/login_password", $headers);
print Dumper $client->responseContent();

Sadly I get back
$VAR1 = '500 Not a SCALAR reference
';


I can't find any hinside the error log of the apache, even with debug 
enabled. I can't find  any thing in the internet that helps me. 
(Perhaps I do not know where to look for).


So any idea where I should look at it to troubleshoot this problem?

You are doing it wrong :)

Have you read my blog article?
https://vda.li/en/posts/2015/05/28/talking-to-freeipa-api-with-sessions/

You need to:
- present referer pointing back to IPA server
- use correct accept header as 'text/plain' for session password logon
- pass username and password in the body of the request, not header,
  encoded ias form parameters 'user' and 'password'

Attached is a simple example that works.

--
/ Alexander Bokovoy


dumpipa.pl
Description: Perl program
-- 
Manage your subscription for the Freeipa-users mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-users
Go to http://freeipa.org for more info on the project