iOS Authentication with aMember 4

Discussion in 'aMember Pro v.4' started by stockguy22, Feb 4, 2012.

  1. stockguy22

    stockguy22 Member

    Joined:
    Jan 18, 2010
    Messages:
    56
    Has anyone tried building an iOS application that authenticates against aMember 4? I want to use ASIHTTPRequest (http://allseeing-i.com/ASIHTTPRequest/How-to-use) but I am not sure what I need to do on the server side to be able to pass credentials to aMember to get a response.

    Do I have to build out something server side to handle authentication? For example, mysite.com/library/Am/Lite.php can't be hit because of the .htaccess rules. Should I be creating an API that will require /path/to/Am/Lite.php and build my own authentication that will send a response?
  2. stockguy22

    stockguy22 Member

    Joined:
    Jan 18, 2010
    Messages:
    56
    To continue on from my original post, this was sent to support. There is a lack of documentation on how to use Di per the API/Authentication page, so I'm trying to get a clear understanding. When / if support gets back to me, I can try to update here. I think this is a great step because this iOS app will be a selling point for some of our leads.

    -- start support e-mail
    We are building an iOS app to authenticate against our aMember installation. My biggest issue is how to use the Di controller. Per this page: http://www.amember.com/docs/API/Authentication, we see:

    Am_Di::getInstance()->authUser->getUser(); // returns User object or null Am_Di::getInstance()->authUser->getUserId() // returns user_id or null
    How do we use it to return a simple JSON response or string, like a success or failure?

    We are currently building the authentication layer in our iPad application and we are posting amember_user and amember_pass to http://amemberURL.com/login/index. We see an HTML response with the wrong username and password that simply states that it's wrong (per the 2 requests below). The next two requests are a POST and GET, which looks like after the login is successful we receive a GET and redirected to /member. That was a successful, but we received an HTML response. Again, is there a way to just get a "yes" or "no" response for authenticating?

    IP - - [04/Feb/2012:12:03:42 -0500] "POST /login/index HTTP/1.1" 200 2049 "-" "sg22 1.0 (iPad Simulator; iPhone OS 5.0; en_US)"
    IP - - [04/Feb/2012:12:05:43 -0500] "POST /login/index HTTP/1.1" 200 2051 "-" "sg22 1.0 (iPad Simulator; iPhone OS 5.0; en_US)"
    IP - - [04/Feb/2012:12:07:22 -0500] "POST /login/index HTTP/1.1" 302 589 "-" "sg22 1.0 (iPad Simulator; iPhone OS 5.0; en_US)"
    IP - - [04/Feb/2012:12:07:22 -0500] "GET /member HTTP/1.1" 200 2256 "-" "sg22 1.0 (iPad Simulator; iPhone OS 5.0; en_US)"

    Is there a way to use Am_Lite to login a user? To recieve a success or failure?
  3. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    There is the code
    PHP:
    <?php
    require '/pathtoamember/bootstrap.php';
    $result Am_Di::getInstance()->auth->login($_POST['login'], $_POST['passwd'], $_SERVER['REMOTE_ADDR']);
    if (
    $result->isValid())
    {
         
    // check if user has access
         
    $products Am_Di::getInstance()->auth->getUser()->getActiveProductIds();
         if (
    in_array(123$products))
             echo 
    "OK, user subscribed to product #123";
         else
             echo 
    "Error, user is not subscribed to product #123";
    } else {
        echo 
    "Username or password incorrect";
    }
    skippybosco likes this.
  4. stockguy22

    stockguy22 Member

    Joined:
    Jan 18, 2010
    Messages:
    56
    Ah so this will work outside of amember directory where as a plugin would be inside. Very nice.
  5. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    That is not a plugin, just a standalone PHP page you may put anywhere on your website (outside of aMember folder) and here you can provide any services based on user authentication.
  6. stockguy22

    stockguy22 Member

    Joined:
    Jan 18, 2010
    Messages:
    56
    Correct. That's what I meant. :)
  7. superlativesmagazine

    superlativesmagazine New Member

    Joined:
    Jan 18, 2010
    Messages:
    5
    hey Stockguy -- how did you manage to pass the login credentials securely to your php script? -- I'm trying to integrate amember authetication into an iPad app as well

Share This Page