0

I use teamwork project management tool. I am trying to create a web app using the REST api given by teamwork. But this requires some authentication. I have read teamwork documentation and this is what they have said

Authentication

Authentication is managed using HTTP authentication (only "Basic" is supported right now). Every request must include the Authorization HTTP header. Use your API token as the username, and "X" (or some otherwise bogus text) as the password (only the API token is used for authenticating API requests).

Example with Curl:

curl -H 'Accept: application/json' -H 'Content-Type: application/json' \
-u APIKEY0123456789:xxx -d '{"request": {"name": "some value"}}' https://yours.teamwork.com

I looked into some online tutorial and wrote following code

public function portalLogin()
{
        //cURL
        // phpinfo(); //curl is enabled
    $channel = curl_init();
    //options
    curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
    curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("secretApiCode:xxx")));
    echo curl_exec($channel);  //return 1
    curl_close($channel);
}

This returns 1. I do not know what it means. I do not know if I am doing the right thing. This is where the teamwork api is which is protected by authentication.

http://projects.abounde.com/projects.json

my end goal is to give different users different username and password which they will enter and system will find the secret key from the database and load the project list from the particular user.

Nurul Alam
  • 342
  • 3
  • 22

1 Answers1

1
public function portalLogin()
{
        //cURL
        // phpinfo();
    $username = "night720elvis";
    $password = "xxx";
    $channel = curl_init();
    //options
    curl_setopt($channel, CURLOPT_URL, "http://projects.abounde.com/projects.json?status=LATE");
    //curl_setopt($channel, CURLOPT_HTTPHEADER, array("Authoritation:BASIC".base64_encode("night720elvis:xxx")));

    curl_setopt($channel, CURLOPT_HTTPHEADER,
                array(
                  "Authorization: Basic " . base64_encode($username . ":" . $password)
    ));
    echo curl_exec($channel);
    curl_close($channel);
}

This authenticates

Nurul Alam
  • 342
  • 3
  • 22