POWER BI Rest API Authentication using PHP - php

I am trying to authenticate using REST APIs, on my PHP backend. However, I am unable to obtain the auth code or access token.
I've registered my application on https://dev.powerbi.com/apps as a server side web-app, and have selected "Read and Write Datasets" permission on the
This is my code :
$url = "https://login.windows.net/common/oauth2/authorize"."?response_type=code"."&client_id=<my_client_id>"."&resource=https://analysis.windows.net/powerbi/api"."&redirect_uri=<my_redirect_url>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$head = curl_exec($ch);
curl_close($ch);
When I run this code, literally nothing happens. It doesn't redirect to my redirect URI.

Related

API I'm using can't be accessed unless Captcha is completed

I am trying to access API data from CraftingStore Public API.
When I am trying it on localhost, everything works like it should (1st pic, also printing results for to show).
However, when I am trying to view it on the actual website (2nd pic), it is not working but instead saying to enable cookies and to complete captcha.
When on localhost:
When on website:
Also code for accessing the API:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.craftingstore.net/v7/payments?page=1');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'token:'.$cs_token
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
$dononame = $obj->data[0]->inGameName;
$donobuy = $obj->data[0]->packageName;
What can I do?
This is quite usual for API's with Cloudflare. You'll need to make a page rule for the API domain/URI to disable the Browser Integrity Check.
Source: https://support.cloudflare.com/hc/en-us/articles/200504045-Using-Cloudflare-with-your-API

Google API Key Http referrers issue

I am using PHP cURL to retrieve Google book information using my Google API key, but getting ipRefererBlocked error whenever I put any http referrer. Any idea please?
HTTP referrers
http://mylibrarymanager.com/*
https://mylibrarymanager.com/*
http://www.mylibrarymanager.com/*
https://www.mylibrarymanager.com/*
www.mylibrarymanager.com/*
Code
$url = 'https://www.googleapis.com/books/v1/volumes?q=isbn:9788420636641&projection=lite&maxResults=1&printType=books&key='.$myApiKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$json = curl_exec($ch);
curl_close($ch);
Since you are calling the API from a server-side PHP script, you should use a server API key rather than a browser API key.

Download audio file using cUrl where authentication required to get file

I want to download a audio file from the server.
When I access the url direct on server that asks for a username & password I want to override it through cURL
Basically I want to allow my web users listen songs on my website. I have an authentication of other web to do so. currently users of my website have double check first they login in my website using credentials after that when they click on Play button then they enter again username & password that I am providing them (of the same web from i have authentication).
$url="https://example.com/abc.wav";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "userstring:passString");
curl_exec($ch);
curl_close($ch);
Direct URL after entering the username & password allowed me to listen the audio.
now how can I authenticate my web to access that URL by overriding authentication?
I want to download it and as well as play in the background after clicking on button "download" & "Play" respectively.
On the other hand is there any way that I can email that file without downloading or by downloading it
Use following code for authentication you forgot to set the header
header("Content-Type: audio/mpeg");
$url = "clip.mp3"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "password");
curl_exec($ch);
header('Location: ' . $url);

PHP - How to login via curl and download files?

Im using php, using curl Im accessing a directory on a server via http using httpauth. I pass it a username and password and it seems to work, but once I login how do I get the current directory and then proceed to download the files in that directory? Im using this curl code to authenticate:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
Just resend the credentials for any future requests. HTTP authentication doesn't keep track of logins; the client simply needs to resend the username / password pair for each request.

Review Board Authentication

I have a review board running on different server . I am using review board as a normal user of it and can comment on the reviews create it but i am not the admin f it. In order to view the review request or comment on it, i need to authenticate with it with my username and password. This is the access given to me. Review Board is an open source tool which is used by many organisations.
Here are the WEB API of it:- (authenticating link) http://www.reviewboard.org/docs/manual/1.5/webapi/2.0/authenticating/#logging-in
Now i am using wamp as server on my local system . I am using php as server side language. I want to use the Review Board API for fetching the data with my credientals. I am using php curl and written this code for authenticating:-
<?php
$ch = curl_init('http://SERVERIP');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic realm="Web API"'));
$output = curl_exec($ch);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Basic md5encryptedusernamepassword'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);
var_dump($output);
?>
This code is not authenticating. Please have a look. Any kind of guideline will be helpful. I have spent much time understanding it. Please help.
You should set headers with key:"Authorization",value:" Basic #{Base64.encode64("username:password")}"。
Then you can access the api which is need authentication.

Categories