I ma having an issue with getting my access token. I know I have allowed access in the settings in my app. I can read my email with there text page:
I can use the token they provide and retrieve it. But I need to be able to get my own token of course. When I have code below it opens the login page and says "There was an issue looking up your account. Tap Next to try again."
Am I using the right API?
$curl = curl_init();
$auth_data = array(
"Content-Type: application/x-www-form-urlencoded",
'client_id' => 'my-client-id',
'response_type' => 'code',
'redirect_uri' => 'https://myurl.com/authorize.php',
'response_mode' => 'query',
'scope' => 'https://graph.microsoft.com/.default',
'state' => '12345'
);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $auth_data);
curl_setopt($curl, CURLOPT_URL, "https://login.microsoftonline.com/{my_tenant_id}/oauth2/v2.0/authorize");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($curl);
if(!$result){die("Connection Failure");}
curl_close($curl);
//echo $result;
var_dump($result);
//print_r($result);
Related
I have been unable to get an OAuth token. I have spent about 4 hours trying. The various iterations and changes the Twitch API has been through is leaving me unsure and confused. The Twitch Developers now have a message posted stating V5 API being decommission on February 28th 2022. I am lost.
This is where I am at right now. The "code" below is from the Getting authorization code here.
<?php
function file_get_contents_curl($url) {
$curlHeader = [
'client_id' => '"CLIENT ID"',
'client_secret' => '"CLIENT SECRET"',
'code' => '"POST TOKEN"',
'grant_type' => '"AUTHENTICATION CODE"',
'redirect_uri' => 'https://rons-home.net'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeader);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
print_r( file_get_contents_curl( 'https://id.twitch.tv/oauth2/authorize' ) );
Response
{"status":400,"message":"missing response type"}
This is a valid curl call to do the Step 3 of user oAuth
Most notably:
you were trying to pass paramters as a header
And you have extra " littered in your paramerters
And your grant type if very wrong
Substitute the constants as needed.
$ch = curl_init('https://id.twitch.tv/oauth2/token');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_id' => CLIENT_ID,
'client_secret' => CLIENT_SECRET,
'code' => $_GET['code'],
'grant_type' => 'authorization_code',
'redirect_uri' => REDIRECT_URI
));
// fetch the data
$r = curl_exec($ch);
// get the information about the result
$i = curl_getinfo($ch);
// close the request
curl_close($ch);
Simple question I am sure. But I am new to the Google Group Admin-SDK and I want to authenticate using php and CURL:
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"code" => $code,
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => $redirect_uri,
"grant_type" => "authorization_code"
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
$authObj = json_decode($json_response);
Most of this I understand, except I can't figure out where the value of the parameter "code" comes from. I hope someone can help me understand how I can get a valid "code" for this application.
BTW I don't want to use a code library in this situation, just php and CURL similar to the above.
Thanks
TimS
I created a little app which uses Pushbullet's API.
It is writtent in PhP and uses cURL to proceed the different requests.
At first, I use oauth2 to recieve an access token.
Then it is /v2/pushes/ to send a push to the registred account.
The message is recieved on the Pusbullet account but nothing shows up on the smartphone. There is no notification.
I hope someone can help me.
Thanks.
My function which sends the push:
function send_push($token){
$data = array(
'type' => 'note',
'title' => 'Alert',
'body' => 'My body :)!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pushbullet.com/v2/pushes');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$token
));
$data = curl_exec($ch);
curl_close($ch);
}
I want to create a webhook url for pitifuller form by id here is my code i don't know what is my mistake
define('CLIENT_ID', 'client_id');
define('CLIENT_SECRET', 'client_secret');
define('REDIRECT_URL', 'redirect url'); // for testing, use the URL to this PHP file.
define('AUTHORIZE_URL', 'https://www.formstack.com/api/v2/oauth2/authorize');
define('TOKEN_URL', 'https://www.formstack.com/api/v2/oauth2/token');
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'redirect_uri' => REDIRECT_URL,
'client_secret' => CLIENT_SECRET,
'id' => 'id', // here is my id
'url' => 'web_hook_url' // here is my webhook url which i want to create
)));
// oauth2 contains the the access_token.
$oauth2 = json_decode(curl_exec($ch));
You did mistake in your CURL call, currently you are pass post data in GET form and you need to pass Like this(POST form/:id/webhook), and you can do this:
$ch = curl_init('https://www.formstack.com/api/v2/form/your-form-id/webhook');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $oauth2->access_token
));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
'id' => $_POST['id'],
'url' => 'http://www.getbravo.com/formstack/index.php',
'append_data' => '1'
)));
and you get response like this
$forms = json_decode(curl_exec($ch));
print '<pre>';
print_r($forms);
print '</pre>';
I have the following code in php:
define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");
$arrData = array(
'grant_type=client_credentials',
'client_id='.CLIENT_ID,
'client_secret='.urlencode(ACCESS_KEY),
'scope=urn%3aWindowsAzureMediaServices'
);
$arrHeader = array(
'Content-length:'.strlen($this->generateData($arrData))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$arrToken = json_decode($data);
I am unable to get the token code. Please can anyone check what could be wrong?
There could be a few issues:
You could simplify a few things and use http_build_query():
$data = http_build_query(array(
'grant_type' => 'client_credentials',
'client_id' => CLIENT_ID,
'client_secret' => ACCESS_KEY,
'scope' => 'urn:WindowsAzureMediaServices',
));
$ch = curl_init(TOKEN_URL);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (($res = curl_exec($ch)) === false) {
die(curl_error($ch));
}
$arrToken = json_decode($res);
If there's an error, the first thing to make sure is whether you have an updated list of CA certificates.