Authorizing with LibCurl in C

New to the API and I’m trying to enter a user’s credentials to authorize my app.

So far I have,

int main(int argc, char** argv){

    CURL* curl;
    CURLcode res;

    prog = argv[argc-argc];

    char* credentials[128] = {"name=USERNAME&password=PASSWORD"};

    curl_global_init(CURL_GLOBAL_DEFAULT);

    curl = curl_easy_init();

    if(curl){
        curl_easy_setopt(curl, CURLOPT_URL, "https://api.twitch.tv/kraken/oauth2/authorize?response_type=code&client_id=CORRECT_CLIENT_ID&redirect_uri=https://localhost/&scope=user_read");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, credentials);
        curl_easy_setopt(curl, CURLOPT_USERAGENT, "atest/1.0");
        curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);

        res = curl_easy_perform(curl);

        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed %s\n", curl_easy_strerror(res));

        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();

    return EXIT_SUCCESS;
}

It seems like it’s getting to the authorization page but not POST’ing the user credentials to authorize with the given client_id.

Twitch employs the OAuth 2 spec and doesn’t allow apps to use the password grant flow, so you have no ability to POST your username and password to Twitch to get a token.

Follow the step by step instructions at https://github.com/justintv/Twitch-API/blob/master/authentication.md#authorization-code-flow on how to integrate Twitch authentication.

Ah, I see now. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.