Пример #1
0
function getToken($client_secret, $client_id, $grant_type, $username = false, $password = false, $refresh_token = false, $response_type = false, $code = false, $redirect_uri = false)
{
    $method = "GET";
    $endpoint = endpointWith("/api/v1/token", $method);
    global $verbose;
    checkAuth();
    $data = array("client_secret" => $client_secret, "client_id" => $client_id, "grant_type" => $grant_type, "username" => $username, "password" => $password, "refresh_token" => $refresh_token, "response_type" => $response_type, "code" => $code, "redirect_uri" => $redirect_uri);
    if ($method != "GET") {
        $data = formattedParametersWithData($endpoint, $data);
    }
    $newPath = fillEndpointPathWithRequirements($endpoint, $data);
    $data = cleanEndpointRequirementsFromData($endpoint, $data);
    return sendGET(defaultHeader(), $data, $newPath);
}
Пример #2
0
function makeMember()
{
    global $piOptions;
    // Make a random email
    $reg = "will\\+[a-z]{7}@quadland\\.com";
    $email = getReverseRegex($reg);
    // Make a random username
    $reg = "[a-z]{7}";
    $username = getReverseRegex($reg);
    // Create the body data.
    $makeBody = array('city' => 'Winston Salem', 'email' => $email, 'firstName' => 'Test', 'country' => 'USA', 'username' => $username, 'lastName' => 'Quadland', 'state' => 'NC', 'streetAddress' => '720 W 5th St', 'phoneNumber' => '5558675309', 'mobileNumber' => '5558675309', 'zipPostalCode' => '27101');
    // Send the POST to make the member
    $content = sendPOST(defaultHeader(), $makeBody, '/api/v1/members');
    // Save the token. We need it to
    //  confirm the member.
    $token = $content["Token"];
    // Next request: Register the member
    $data = array("token" => $token, "member" => $email, "password" => array("password" => "pass1", "confirm" => "pass1"));
    // API path
    $path = '/api/v1/members/' . $email . '/registrations/' . $token;
    // Send the request
    $content = sendPATCH(defaultHeader(), $data, $path);
    // Next request: Authorize the user (AKA login).
    $authPath = '/api/v1/token';
    // Hardcoded stuff needs to be changed at some point...
    //$authQstr = '?client_secret=1nf0oilqavc0g4ock8k800cswgoo0s04wgk8skgcg00044ogog&client_id=2_2f1e18hbyyasgoco40o00o0k4c0ksccg0kso44ok80w8884w08&grant_type=password&username='******'&password=pass1';
    $params = array("client_secret" => $piOptions["client_secret"], "client_id" => $piOptions["client_id"], "grant_type" => "password", "username" => $email, "password" => "pass1");
    // Send the login request
    $content = sendGET(defaultHeader(), $params, $authPath);
    // Return the needed info...
    return array("member" => $email, "token" => $content["access_token"], "password" => array("password" => "pass1", "confirm" => "pass1"));
}