I'm really having a difficult time trying to find a way to successfully authenticate a user and post a bookmark to their delicious account.
I downloaded Yahoo's YOS Social SDK then began modifying the oauth sampleapp.php. It basically handles the oAuth process by creating a login link that sends you to Yahoo to grant permission then sends you back to the callback URL you specify.
My thought was to modify the sampleapp.php file to make a request to delicious posts/add API to add a new bookmark once they oAuth process is over, but I'm running into some problems. I think I'm handling the POST request in the wrong manner.
Here is my code:
<?php
require dirname(__FILE__).'/lib/Yahoo.inc';
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', true);
YahooLogger::setDebug(true);
YahooLogger::setDebugDestination('LOG');
ini_set('session.save_handler', 'files');
session_save_path('/tmp/');
session_start();
define('OAUTH_CONSUMER_KEY', '<YOURS_GOES_HERE>');
define('OAUTH_CONSUMER_SECRET', '<YOURS_GOES_HERE>');
define('OAUTH_DOMAIN', '<YOURS_GOES_HERE>');
define('OAUTH_APP_ID', '<YOURS_GOES_HERE>');
if(array_key_exists("logout", $_GET)) {
YahooSession::clearSession();
header("Location: sampleapp.php");
}
$hasSession = YahooSession::hasSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($hasSession == FALSE) {
$callback = YahooUtil::current_url();
$auth_url = YahooSession::createAuthorizationUrl(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback);
}
else {
$session = YahooSession::requireSession(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_APP_ID);
if($session) {
$consumer = new stdclass();
$consumer->key = OAUTH_CONSUMER_KEY;
$consumer->secret = OAUTH_CONSUMER_SECRET;
$nativeSession = new NativeSessionStore();
$token = $nativeSession->fetchAccessToken();
$client = new OAuthClient($consumer, $token, OAUTH_PARAMS_IN_HEADERS, OAUTH_SIGNATURE_HMAC_SHA1);
$request_url = 'http://api.del.icio.us/v2/posts/add';
$bookmark_url = 'http://www.tegdesign.com';
$parameters = array("url" => urlencode($bookmark_url), "description" => "test");
$response = $client->post($request_url,'TEXT',$parameters);
echo '<pre>';
print_r($response);
echo '</pre>';
}
}
if($hasSession == FALSE) {
echo sprintf("Login\n", $auth_url);
} else if($hasSession) {
echo "<p>Logout</p>";
}
?>
And here is the output of $response variable:
Array
(
[method] => POST
[url] => http://api.del.icio.us/v2/posts/add
[code] => 401
[requestHeaders] => Array
(
[0] => Accept: application/json
[1] => Authorization: OAuth realm="yahooapis.com",oauth_version="1.0",oauth_nonce="<MINE_SHOWS_HERE>",oauth_timestamp="1289407587",oauth_consumer_key="<MINE_SHOWS_HERE>",oauth_token="<MINE_SHOWS_HERE>",oauth_signature_method="HMAC-SHA1",oauth_signature="<MINE_SHOWS_HERE>"
[2] => Content-Type: TEXT
)
[requestBody] => Array
(
[url] => http%3A%2F%2Fwww.tegdesign.com
[description] => test
)
[responseHeaders] => Array
(
[Date] => Wed, 10 Nov 2010 16:46:32 GMT
[WWW-Authenticate] => OAuth oauth_problem="signature_invalid", realm="yahooapis.com"
[Content-Type] => application/json
[Cache-Control] => private
[Age] => 0
[Transfer-Encoding] => chunked
[Connection] => keep-alive
[Server] => YTS/1.17.21
)
[responseBody] => {"error":{"lang":"en-US","description":"Please provide valid credentials"}}
)
Does anybody have knowledge on using Delicious new API to successfully authenticate and post a bookmark on behalf a user? I'm having a terrible time.
Thanks,
Tegan
Set your content type to "application/x-www-form-urlencoded" instead of 'Text' on the below line.
$response = $client->post($request_url,'TEXT',$parameters);
Related
As with most people, Microsoft are turning off basic authentication. This means we need to use Modern Auth to retrieve emails from a mailbox.
However,when we retrie the access token fails with "
Client error: `POST https://login.microsoftonline.com/aea9a7d8-73fb-41af-987b-6fe14277421e/oauth2/v2.0/token` resulted in a `400 Bad Request` response:\n
{"error":"unauthorized_client","error_description":"AADSTS700016: Application with identifier '\"014438b9-82dc-4a4c-9584 (truncated...)
"
Here is the code we have for retrieving and connecting to IMAP. I am passing actual email and password in usename and password field
/* Get the access Token */
$Secret = '**REMOVED**';
$AppID = '**REMOVED**';
$TenantID = '**REMOVED**';
$AccessToken = '';
try {
$guzzle = new \GuzzleHttp\Client(['headers' => ['User-Agent' => 'App-Token-Request']]);
$url = 'https://login.microsoftonline.com/'.$TenantID.'/oauth2/v2.0/token';
$token = json_decode($guzzle->post($url, [
'form_params' => [
'grant_type' => 'password',
'client_id' => $AppID,
'client_secret' => $Secret,
'scope' => 'https://graph.microsoft.com/.default', //'https://outlook.office365.com/IMAP.AccessAsUser.All',// 'https://graph.microsoft.com/.default',
'username' => '**REMOVED**',
'password' => '**REMOVED**',
],
])->getBody()->getContents());
$this->info(var_dump($token));
$AccessToken = $token->access_token;
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
dd($e);
return redirect('/')->with('error', 'Error requesting access token')->with('errorDetail', json_encode($e->getResponseBody()));
}
I want to connect -any- customer Google AdWords Account with Google Login. (Like Wordstream)
I prepared a code, but there is a problem somewhere, I can't run it.
When the customer press the connect button, the screen appears. It says "XXX wants to acces your Google Account", it is approved but I cannot receive data.
How can i get datas from customer's account?
Code:
require 'google-api/vendor/autoload.php';
use Google\Auth\OAuth2;
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\CampaignService;
use Google\AdsApi\Common\OAuth2TokenBuilder;
session_start();
$oauth2 = new OAuth2([
'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth',
'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token',
'redirectUri' => 'https://xxxxx.xxxxxx',
'clientId' => 'xxxxxxxxx.apps.googleusercontent.com',
'clientSecret' => 'xxxxxxxxxxx',
'scope' => 'https://www.googleapis.com/auth/adwords',
'refresh_token' => 'xxxxxxxxxx'
]);
if(!isset($_GET['code'])){
$oauth2->setState(sha1(openssl_random_pseudo_bytes(1024)));
$_SESSION['oauth2state'] = $oauth2->getState();
$config = [
'access_type' => 'offline',
'prompt' => 'consent',
];
header('Location: ' . $oauth2->buildFullAuthorizationUri($config));
exit;
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])){
unset($_SESSION['oauth2state']);
exit('Invalid state.');
} else {
$oauth2->setCode($_GET['code']);
$authToken = $oauth2->fetchAuthToken();
$refreshToken = $authToken['refresh_token'];
$path = "xxxxx/google-api/vendor/adsapi_php.ini";
$session = (new AdWordsSessionBuilder())
->fromFile($path)
->withOAuth2Credential($oauth2)
->build();
$adWordsServices = new AdWordsServices();
$campaignService = $adWordsServices->get($session, CampaignService::class);
print_r($campaignService);
}
I am having issues with refreshing tokens with the xero api. When I first create the token, everything is fine. When I refresh the token, I get authentication unsuccessful.
{"Type":null,"Title":"Forbidden","Status":403,"Detail":"AuthenticationUnsuccessful","Instance":"8d6256e5-3376-4960-be52-cf8b22ee241c","Extensions":{}}
My code is as follows:
public function refreshToken()
{
$provider = new GenericProvider([
'clientId' => $valuestore->get('client_id'),
'clientSecret' => $valuestore->get('client_secret'),
'redirectUri' => $valuestore->get('callback_url'),
'urlAuthorize' => 'https://login.xero.com/identity/connect/authorize',
'urlAccessToken' => 'https://identity.xero.com/connect/token',
'urlResourceOwnerDetails' => 'https://api.xero.com/api.xro/2.0/Organisation'
]);
$newAccessToken = $provider->getAccessToken('refresh_token', [
'refresh_token' => $this->getRefreshToken()
]);
// Save my token, expiration and refresh token
$this->setOauth($newAccessToken);
}
public function setOauth($accessToken)
{
$oauth2 = [
'token' => $accessToken->getToken(),
'expires' => $accessToken->getExpires(),
'tenant_id' => $this->getTenantId(),
'refresh_token' => $accessToken->getRefreshToken(),
'id_token' => $accessToken->getValues()["id_token"]
];
//set session
}
Thanks in advance
Regards
Danny
I used the following code to try to grab tweets from my home_timeline
$tmhOAuth = new tmhOAuth(array('consumer_key' => TW_KEY,
'consumer_secret' => TW_SECRET,
'user_token' => TW_UTOKEN,
'user_secret' => TW_USECRET,
));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/home_timeline', 'json'));
The $tmhOAuth came from this library here: https://github.com/themattharris/tmhOAuth
For some reason, only one tweet is showing, and it's my most recent one. All my old tweets are not visible. When I change the secrets and keys to that of another user-app, i have similar problme, some tweets are visible while others are not. Does anyone know why it doesnt' just grab all X number of the most recent tweets? Why are some tweets missing?
I download Jimbo's API from github and then did hte following code
<?php
ini_set('display_errors', 1);
require_once('twjimbo/TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => '',
'consumer_secret' => ""
);
]
$url = 'https://api.twitter.com/1.1/statuses/home_timeline.json';
$getfield = '?screen_name=anythingworkshere';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
echo '<pre>'; print_r(json_decode($json)); echo '</pre>';
In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.