User authentication via XML-RPC

Discussion in 'Integration' started by eugenez, Jun 15, 2011.

  1. eugenez

    eugenez New Member

    Joined:
    Jun 15, 2011
    Messages:
    4
    Hello,

    I am developing a software for my client and he wants to use amember for billing. My goal is to create own login form and urls/paths protection code. My software is written in python (fastcgi) and uses bit strange urls scheme, so I don't like mod_rewrite and other protection methods described here: http://manual.amember.com/Protection_Methods. Basically I need a way to ask amember about user's login/password validity and check if user has access (subscription active) to required product. I see 2 variants how to do this:

    1) make SQL queries to amember mysql database from my code. Do not want to do this because my software uses another database system (so I must maintain another connection pool for mysql, etc). Also I can have problems if database structure will be changed after amember upgrade or something.

    2) use XML-RPC API. I found example of "get_user" function usage and can use it to check if user has access to required product (data["status"][product_id] if I understand right). But what XML-RPC method can be used to validate login/password pair and receive member_id ? I think it must be "check_login" but can't find example how to call it right way. Can't find something helpful in manual/forum. I'm playing with trial version of amember - source code is encrypted, so I don't have opportunity to review it.

    Please help me.

    P.S.: sorry for long text and bad English.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Hi,
    you can use check_uniq_login xmlrpc method. You should pass array to that method:
    $u = array(
    'login' =>$login,
    'pass' => $pass,
    'email' => $email,
    'check_type' =>2
    )

    return member_id if user exists, -1 if no and 0 if email/password failed
  3. eugenez

    eugenez New Member

    Joined:
    Jun 15, 2011
    Messages:
    4
    Hello,

    Thank you for reply, Alexander. But I have some troubles with your solution:

    "select member_id, login, pass, email from amember_members;" SQL query returns following:

    | 2 | test | test | test@example.com |

    I'm using this code (python) for testing:

    import xmlrpclib
    srv = xmlrpclib.ServerProxy("http://rpc_login_here:rpc_password_here@my_domain_here/amember/xmlrpc/index.php")
    srv.check_uniq_login({"login": "test", "pass": "test", "email": "test@example.com", "check_type": 2})

    And server returns -1 to me. Don't understand where is a problem.


    And another small question: is any way to authenticate using only login (or only email) + password present? Login form that asks both login and email looks bit strange as for me.
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Yes sorry I misunderstood you.
    You should use check_login call it accept just login and password: array('login'=>$login, 'pass'=>$pass)
    return member_id if authentication is ok
    0 if failed.
  5. eugenez

    eugenez New Member

    Joined:
    Jun 15, 2011
    Messages:
    4
    Thank you again for reply, Alexander. But seems I'm doing something wrong:

    In database I have following record:

    mysql> select member_id, login, pass, email from amember_members;"
    +-----------+-------+-------+------------------+
    | member_id | login | pass | email |
    +-----------+-------+-------+------------------+
    | 2 | test | test | test@example.com |
    +-----------+-------+-------+------------------+


    Using following python code for testing:

    import xmlrpclib
    srv = xmlrpclib.ServerProxy("http://rpc_login_here:rpc_password_here@my_domain_here/amember/xmlrpc/index.php")
    srv.check_login({"login": "test", "pass": "test"})

    And amember returns "" (blank string) :( The same happens if I call check_login with wrong login/password values. For wrong call like srv.check_login("test", "test") it returns 0.

    My amember version is 3.2.3TRIAL (from Utilities -> Version info), php version is 5.3.3 if this matters.
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Well I just verified code and found an error.
    this function accept one parameter and this is array of parameters. I'm not sure why this was done in first place. So you should pass array(array('login'=>'login', 'pass'=>'pass'))
    here is working example :
    Code:
    #!/usr/bin/python
    import xmlrpclib
    
    proxy = xmlrpclib.ServerProxy("http://test:test@localhost/amember/xmlrpc/index.php")
    print proxy.check_login([{'login' : 'test', 'pass' : 'test'}])
    
    
  7. eugenez

    eugenez New Member

    Joined:
    Jun 15, 2011
    Messages:
    4
    It works now! Thank you, Alexander. We will buy amember soon, because it is the best software for users management that I seen. But will be nice to have good documentation for developers/software integrators someday :)

Share This Page