I am getting following error in Azure Authentication. Kindly help me understand the same.
Fatal error: Uncaught exception
'League\OAuth2\Client\Provider\Exception\IdentityProviderException'
with message 'invalid_client' in
/var/www/html/active/vendor/league/oauth2-client/src/Provider/GenericProvider.php:216
Stack trace: #0
/var/www/html/active/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(644):
League\OAuth2\Client\Provider\GenericProvider->checkResponse(Object(GuzzleHttp\Psr7\Response),
Array) #1
/var/www/html/active/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(560):
League\OAuth2\Client\Provider\AbstractProvider->getResponse(Object(GuzzleHttp\Psr7\Request))
2 /var/www/html/active/src/Delegates/Receive.php(82): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken('authorization_c...',
Array) #3 /var/www/html/active/src/ActiveDirectory.php(180):
Magium\ActiveDirectory\Delegates\Receive->execute() #4
/var/www/html/active/index.php(25):
Magium\ActiveDirectory\ActiveDirectory->authenticate() #5 {main}
thrown in
/var/www/html/active/vendor/league/oauth2-client/src/Provider/GenericProvider.php
on line 216
I have the following code
<?php
ini_set('display_errors', 1);
require_once 'vendor/autoload.php';
session_start();
$config = [
'authentication' => [
'ad' => [
'client_id' => 'xxx',
'client_secret' => 'xxx',
'enabled' => '1',
'directory' => 'common'
]
]
];
$request = new \Zend\Http\PhpEnvironment\Request();
$ad = new \Magium\ActiveDirectory\ActiveDirectory(
new \Magium\Configuration\Config\Repository\ArrayConfigurationRepository($config),
Zend\Psr7Bridge\Psr7ServerRequest::fromZend(new \Zend\Http\PhpEnvironment\Request())
);
$entity = $ad->authenticate();
echo $entity->getName() . '<Br />';
// echo $entity->getOid() . '<Br />';
echo $entity->getPreferredUsername() . '<Br />';
URL : https://github.com/magium/active-directory
Kindly help.
Microsoft automatically signs in using the client id which is used first time. If it is a wrong one, it will always throw this error even if it is updated in .env file. How to overcome this?
Go to Apps & Services page
Click on Edit against the app you are trying to sign in
Click on Remove these permissions button
Try to authenticate again
Related
I've followed this tutorial to make a media upload to the twitter API. The text upload works perfectly, but if I want to upload a media, I get the error:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'You must supply a readable file' in /hp/be/ac/on/www/vendor/abraham/twitteroauth/src/TwitterOAuth.php:297 Stack trace: #0 /hp/be/ac/on/www/vendor/abraham/twitteroauth/src/TwitterOAuth.php(266): Abraham\TwitterOAuth\TwitterOAuth->uploadMediaNotChunked('https://upload....', Array) #1 /hp/be/ac/on/www/posten.php(288): Abraham\TwitterOAuth\TwitterOAuth->upload('https://upload....', Array) #2 {main} thrown in /hp/be/ac/on/www/vendor/abraham/twitteroauth/src/TwitterOAuth.php on line 297
This is my code:
$twitter = new TwitterOAuth(
$config['consumer_key'],
$config['consumer_secret'],
$OAuthToken,
$OAuthTokenSecret
);
$post_media = $twitter->upload('media/upload', ['media' => "/uploads/Bilder/1.png"]);
/**$parameters = [
'status' => "Test description",
'media_ids' => implode(',', [$post_media->media_id_string])
];
$result = $twitter->post('statuses/update', $parameters);**/
Like you see, I've even commented the part, beginning at $parameters, but that didn't change the result. So the error must be in the upload line.
I've already tried replacing media/upload with https://upload.twitter.com/1.1/media/upload.json as said in https://github.com/abraham/twitteroauth/issues/562, but that didn't help either.
I've checked, that the link /uploads/Bilder/1.png is correct and refers to an image on my server. So, why doesn't the script work?
Does anybody know a solution to this?
It's late to answer, but might help someone. The code below works just perfect!
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $twitter->get("account/verify_credentials");
$tweet = "My tweet";
$imageMedia = $twitter->upload('media/upload', array('media' => '/path/to/image/image_name.png'));
$parameters = array("status" => $tweet, "media_ids" => $imageMedia->media_id_string);
$statuses = $twitter->post("statuses/update", $parameters);
Same problem, different solution.
Answer: "The upload() function requires a local file. An URL will not work, you must download it first."
Look at this issue: https://github.com/abraham/twitteroauth/issues/697
If you want to post image using twitter api at first you must download it first. In fact the upload() function requires a local file.
I'm trying to make woocommerce REST API work. On first sight it apears quite simple by following the doc: https://woocommerce.github.io/woocommerce-rest-api-docs/?php#introduction.
But I struggle making it work.
Here is my code:
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'my_website_uri',
'consumer_key',
'consumer_secret',
[
'wp_api' => true,
'version' => 'wc/v2'
]
);
try{
print_r($woocommerce->get(''));
}
catch (HttpClientException $e) {
print_r($e->getMessage());
print_r($e->getRequest());
print_r($e->getResponse());
}
?>
Here is what i get:
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Syntax error in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346 Stack trace: #0 /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse() #1 /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('', 'GET', Array, Array) #2 /Applications/MAMP/htdocs/WC_REST/test.php(19): Automattic\WooCommerce\Client->get('') #3 {main} thrown in /Applications/MAMP/htdocs/WC_REST/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 346
I wrote down exactly what's in the doc.
I always got an '/wp-json/wc/v2/system_status was not found on this server.' error when enabling the output of $body as suggested above.
I fixed it with enabling permalinks (in admin-backend) which is needed for accessing a slash separated url.
I'm trying to post on my Facebook page with PHP.
I have set up the Facebook API (version 4) and collected all the data I need, like AppId, Secret Key, Access Token and now when I try to post on my page like this:
require 'vendor/autoload.php';
define('FACEBOOK_SDK_V4_SRC_DIR', '/vendor/facebook/php-sdk-v4/src/Facebook/');
define("FACEBOOK_CONSUMER_KEY", "{myKey}");
define("FACEBOOK_CONSUMER_SECRET", "{mySecret}");
define("FACEBOOK_ACCESS_KEY", "{myToken}");
Facebook\FacebookSession::setDefaultApplication(FACEBOOK_CONSUMER_KEY, FACEBOOK_CONSUMER_SECRET);
$session = new Facebook\FacebookSession(FACEBOOK_ACCESS_KEY);
$message = array(
"message" => "It works!",
"link" => "http://www.google.de",
//"picture" => "url to picture",
//"name" => "Picture title",
//"description" => "Description",
);
$response = ( new Facebook\FacebookRequest( $session, 'POST', '/{myPageId}/feed', $message ) )->execute()->getGraphObject();
echo $response->getProperty('id');
Unfortunately I get the following error evertime I execute it:
PHP Fatal error: Uncaught exception 'Facebook\FacebookPermissionException' with message '(#200) The user hasn't authorized the application to perform this action' in {myPath}/FacebookRequestException.php:128
Stack trace:
#0 {myPath}/FacebookRequest.php(280): Facebook\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 403)
#1 {myPath}/test.php(21): Facebook\FacebookRequest->execute()
#2 {main}
thrown in {myPath}/FacebookRequestException.php on line 128
How can I setup the Facebook App that it work correctly?
You have to do the login flow to authorize your app first. https://developers.facebook.com/docs/php/howto/example_facebook_login/4.0.0
Right now i am working on spotify api, When i hit url for first time it is giving me all playlist but when i refresh page again it is giving me exception error, here is my code,
require '../../../vendor/autoload.php';
$session = new SpotifyWebAPI\Session('******', '*******', 'http://localhost:8080/spotify/vendor/jwilsson/spotify-web-api-php/demo.php');
$api = new SpotifyWebAPI\SpotifyWebAPI();
if (isset($_GET['code'])) {
$session->requestAccessToken($_GET['code']);
$data = $api->setAccessToken($session->getAccessToken());
$artistData = $api->me();
$artistId = $artistData->id;
$playlists = $api->getUserPlaylists($artistId, array(
'limit' => 5
));
foreach ($playlists->items as $playlist) {
echo '' . $playlist->name . ' <br>';
}
} else {
$scopes = array(
'scope' => array(
'user-read-email',
'user-library-modify',
),
);
header('Location: ' . $session->getAuthorizeUrl($scopes));
}
Here is my exception error
Fatal error: Uncaught exception 'SpotifyWebAPI\SpotifyWebAPIException' with message 'Invalid authorization code' in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php:156 Stack trace: #0 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php(26): SpotifyWebAPI\Request->send('POST', 'https://account...', Array, Array) #1 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Session.php(233): SpotifyWebAPI\Request->account('POST', '/api/token', Array) #2 D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\demo.php(31): SpotifyWebAPI\Session->requestAccessToken('AQAaVZvpXUExKg2...') #3 {main} thrown in D:\xampp\htdocs\spotify\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 156
Can anyone please tell me why it cause error ? If anyone have experiance with spotify
Creator of the library here.
The only thing I can think of which would yield that error message is if you try to request a access token twice with the same code. Try visiting the URL to your PHP file again but remove any ?code=... parts.
I have been struggling to write a PHP script that will reboot a server using the 1.6.0 version of the Rackspace API (I can't install Composer on my server needed for 1.7.0). Unfortunately it does not want to recognize my credentials and keeps throwing this error:
Fatal error: Uncaught exception 'OpenCloud\Common\Exceptions\CredentialError' with message 'Unrecognized credential secret' in /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/OpenStack.php:694 Stack trace: #0 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/Rackspace.php(66): OpenCloud\OpenStack->credentials() #1 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/OpenStack.php(714): OpenCloud\Rackspace->Credentials() #2 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/OpenStack.php(591): OpenCloud\OpenStack->authenticate() #3 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/OpenStack.php(652): OpenCloud\OpenStack->checkExpiration() #4 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/Common/Service.php(337): OpenCloud\OpenStack->serviceCatalog() #5 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/Common/Service.php(68): OpenCloud\Common\Service->getEndpoint('compute', 'cloudServersOpe...', 'ORD', 'publicURL') #6 /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/ in /home/sandbox/public_html/rackspaceapi/lib/OpenCloud/OpenStack.php on line 694
Here is my PHP script (I did not include my credentials)
require_once "php-opencloud.php";
// The AUTHURL used for the US was: https://identity.api.rackspacecloud.com/v2.0/
putenv("RAX_USERNAME=$username");
putenv("RAX_API_KEY=$apikey");
putenv("RAX_TENANT_NAME=$tenantname");
putenv("RAX_AUTH_URL=$authurl");
define('USERNAME', $_ENV['RAX_USERNAME']);
define('APIKEY', $_ENV['RAX_API_KEY']);
define('TENANT', $_ENV['RAX_TENANT_NAME']);
define('AUTHURL', 'RAX_AUTH_URL');
$rackspace = new \OpenCloud\Rackspace(AUTHURL,
array( 'username' => USERNAME,
'apiKey' => APIKEY ));
$cservers = $rackspace->Compute('cloudServersOpenStack', 'ORD');
$list = $cservers->ServerList();
while($server = $list->Next()) {
if ($server->name == 'My_Server')
$server->Reboot('hard');
}
echo "Reboot sequence complete.";
Any help anyone can offer would be greatly appreciated.