We want to create Quickblox user through our WEB-Java application.
To get the same working we are trying to first make the REST API calls through Postman and CURL and then proceed to Java Code.
However, we are getting 500 internal error
URL
https://api.quickblox.com/session.json
Header
Content-Type: application/json"
QuickBlox-REST-API-Version: 0.1.0
body
{"application_id": “35221”, "auth_key": "wU8JrJ-DKamUB8v", "timestamp": “1456378718”, "nonce": “1112”, "signature": "81f3967265c87de025010eb9298d169555085e91”}
To generate the signature
application_id=35221&auth_key=wU8JrJ-DKamUB8v&nonce=1112×tamp=1456378718
Here is the response we are getting `Connection → keep-alive
Content-Length → 948
Content-Type → text/html; charset=utf-8
Date → Thu, 25 Feb 2016 05:48:08 GMT
Server → nginx/1.8.0
Status → 500 Internal Server Error
X-Rack-Cache → invalidate, pass
X-Request-Id → 3a47c3daaf9ad353a5b592459c6f3345
X-Runtime → 0.003346`
As to my understanding the parameters are as suggested in the API docs. Please help as we are bit stuck at it and are not able to move forward.
Also posting a curl equivalent that results in same error
curl -X POST \
-H "Content-Type: application/json" \
-H "QuickBlox-REST-API-Version: 0.1.0” \
-d '{"application_id": “35221”, "auth_key": "wU8JrJ-DKamUB8v", "timestamp": “1456378718”, "nonce": “1112”, "signature": "81f3967265c87de025010eb9298d169555085e91”}’ \
https://api.quickblox.com/session.json
application_id=35221&auth_key=wU8JrJ-DKamUB8v&nonce=1112×tamp=1456378718
authorisation secret - FEu2AN8CfgU7VF4
thanks,
aakash
First define all the related to the application:
DEFINE('APPLICATION_ID', 23424);
DEFINE('AUTH_KEY', "dfsadfasdfsadf-");
DEFINE('AUTH_SECRET', "23421342134");
DEFINE('USER_LOGIN', "rahul");
DEFINE('USER_PASSWORD', "fghdf56456456");
// Quickblox endpoints
DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com");
DEFINE('QB_PATH_SESSION', "session.json");
After define, create signature and pass $post_body in curl session api hit, get token and use token in all the webservices php:
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."×tamp=".$timestamp."&user[login]=".USER_LOGIN."&user[password]=".USER_PASSWORD;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
));
Related
API Documentation
This is the documentation for the available API endpoints, which are built around the REST architecture. All the API endpoints will return a JSON response with the standard HTTP response codes and need a Bearer Authentication via an API Key.
Base url
https://app.popify.site/api
Retrieve a user
curl --request GET \
--url 'https://app.popify.site/api/user' \
--header 'Authorization: Bearer {api_key}' \
Getting error 401: Missing bearer authentication in header, though I'm using correct api key.
If it is a JWT token you are passing, I'd suggest you to go to JWT decode and paste your encoded token to see what all information it consists. Ideally. roles and user related information is available in payload, if some of it is not enrolled or available on the authorization server, it will result in 401 Unauthorized.
curl --request GET \
--url 'https://app.popify.site/api/user' \
--header 'Authorization: Bearer {api_key}' \
wrap your authorization with quotes and do the same with bearer like this:
--url 'https://app.popify.site/api/user' \
-- header "Authorization ": "Bearer {api key} "
using fetch API:
const result = async getBalance(){
await fetch("https://foma.line.pm/balance", {
method: "get",
headers: {
"Authorization": " Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIU "
}}).then(response => response.json()).then(data => console.log(data)
)
}
This question is about paypal API catalog when try to create a production and to do a subscription.
I'm following this tutorial https://developer.paypal.com/docs/subscriptions/integrate/
I'm able to get my token, but trying to create a product I get "Authorization failed due to insufficient permissions"
Here my code
// GET TOKEN
$paypalcurl = 'curl -v https://api-m.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "'.($paypal_client_id.':'.$paypal_client_secret).'" -d "grant_type=client_credentials"';
$ptoken_result = json_decode(exec($paypalcurl.' 2>&1'),true);
$ptoken = $ptoken_result['access_token'];
// CREATE PRODUCTI AND GET PRODUCT ID
$paypalcurl_create_prodct = 'curl -v -X POST https://api-m.sandbox.paypal.com/v1/catalogs/products \
-H "Content-Type: application/json" \
-H "Authorization: Bearer '.$ptoken.'" \
-d \'{
"name": "Video Streaming Service test",
"description": "Video streaming service",
"type": "SERVICE",
"category": "SOFTWARE",
"home_url": "https://www.example.com/"
}\'';
$pcreate_result = json_decode(exec($paypalcurl_create_prodct.' 2>&1'),true);
if ( ADMIN_PASS == 1 ) { echo str_replace(',',',<br>',var_export($pcreate_result,true)); }
Here the result
array ( 'name' => 'NOT_AUTHORIZED',
'message' => 'Authorization failed due to insufficient permissions.',
'debug_id' => 'f7d1051f9daf3',
'details' => array ( 0 => array ( 'issue' => 'PERMISSION_DENIED',
'description' => 'You do not have permission to access or perform operations on this resource.',
),
),
'links' => array ( 0 => array ( 'href' => 'https://developer.paypal.com/docs/api/v1/billing/subscriptions#NOT_AUTHORIZED',
'rel' => 'information_link',
'method' => 'GET',
),
),
)
What I'm I missing ?
After the comment I realize that it was simply a delay.
1- go to https://developer.paypal.com/developer/applications/
2- click on the app you created
3- there is a checkmark Accept paymentsEnable one-time and subscription payments. Advanced options and CLICK on "Advanced options"
4- checkmark "Billing agreements" and "Future payments" and save
5- wait some hours
6- voilà!
The documentation and help for this particular Segment.io is limited and sparse, so I hope it's OK to ask in here.
I have just set up a Segment.io workspace and a HTTP API source
Per the docs, I sent some POST requests (with Postman) to the https://api.segment.io/v1/track and https://api.segment.io/v1/page endpoints. The requests were structured like this:
curl -X POST \
https://api.segment.io/v1/track \
-H 'Accept: */*' \
-H 'Authorization: My4w3s0m3k3y' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: api.segment.io' \
-H 'Postman-Token: 474d7fbe-15af-43d2-b629-61e15945e662,2c3d5fbe-2c09-4fe6-b7ea-a04e3221201b' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 117' \
-d '{
"userId": "abc123",
"event": "My tests",
"properties": {
"name": "test 1"
}
}'
which all returned a 200 response and the following message:
{
"success": true
}
However, when I got to my dashboard, no events have been recorded.
The debugger is also empty
What am I missing here?
It looks like your write key isn't base64 encoded. When you encode your write key, remember to add the : at the end of it, before it's encoded.
Also, for the Authorization key:value, be sure to add Basic before the encoded write key. So your Authorization key:value would look like:
Authorization: Basic {encoded write key}
An example from the segment documentation:
In practice that means taking a Segment source Write Key,'abc123', as the username, adding a colon, and then the password field is left empty. After base64 encoding 'abc123:' becomes 'YWJjMTIzOg=='; and this is passed in the authorization header like so: 'Authorization: Basic YWJjMTIzOg=='.
I have been dealing with the same issue.
I found the solution as Todd said.
You should add a header Authorization: Basic + base64 encoding write key.
So, you look for the Segment source setting and get the write key.
After that, i have used an online base64 encoding tool to encode my write key.
Finally, you should add this header (Authorization) with 'Basic' and the encoded write key.
You should be able to see the tracked event in the Debugging panel in Segment web page.
I hope this helps!
You can try this code
const { promisify } = require("util");
var Analytics = require("analytics-node");
var analytics = new Analytics("xxxxxxxxxxxxxxxxxxxxxxx", {
flushAt: 1,
});
const [identify, track] = [
analytics.identify.bind(analytics),
analytics.track.bind(analytics),
].map(promisify);
console.log("user id: ", req.body.event.app_user_id);
let app_user_id = req.body.event.app_user_id;
let period_type = req.body.event.period_type;
let expiration_at_ms = req.body.event.expiration_at_ms;
let ret = "Initial";
try {
await identify({
userId: app_user_id,
traits: {
period_type: period_type,
expiration_at_ms: expiration_at_ms,
},
});
ret = "Done : Sengment done";
} catch (err) {
console.log("err: ", err);
ret = "Error : " + err;
}
return {
rafsan: ret,
};
Try to clear your browser's cache or use a different browser. I had the same problem and worked for me.
Hope this helps.
I encounter an issue when I try to use the Paypal sandbox API.
I've created my 2 sandbox accounts (the facilitator and the buyer), and I've created my app to get the credentials.
Then, I use the curl example provided by Paypal to get a token :
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \
-H "Accept: application/json" \
-H "Accept-Language: en_US" \
-u "my-client-id:my-secret" \
-d "grant_type=client_credentials"
I get a 200 response, with an "access_token".
Then, I use this access token to get another resource, for example :
curl -v -X GET https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Then, I get a 401 error :
{
"name":"AUTHENTICATION_FAILURE",
"message":"Authentication failed due to invalid authentication credentials or a missing Authorization header.",
"links":[{
"href":"https://developer.paypal.com/docs/api/overview/#error",
"rel":"information_link"
}]
}
I don't understand what I'm doing wrong, since I've followed every step decribed in the Paypal doc (at least, I think I have... probably not)
Thanks for your help
curl -v -X GET "https://api.sandbox.paypal.com/v1/invoicing/invoices?page=3&page_size=4&total_count_required=true" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer the-token-received-above"
Actually had this exact same issue but didn't know what was wrong with my curl. For me, the issue was I forgot to put "Bearer" in the Authorization section.
For this, you are required to wrap the URL with quotation marks.
After get access_token. Please try this
try {
$params = array('access_token' => $jsonResponse->access_token);
$userInfo = OpenIdUserinfo::getUserinfo($params, $this->_api_context);
} catch (Exception $ex) {
ResultPrinter::printError("User Information", "User Info", null, $params, $ex);
exit(1);
}
ResultPrinter::printResult("User Information", "User Info", $userInfo->getUserId(), $params, $userInfo);
Don't forget to add
use PayPal\Api\OpenIdTokeninfo;
use PayPal\Api\OpenIdUserinfo;
That's worked for me.
I am trying to get OAuth2 token for authorization on my local JHipster server.
Everything is setup correctly and working, I can login via Web GUI.
But when I try to get token via cURL I get POST method not allowed
My cURL request is as following:
curl -X POST -vu client:secret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=admin&password=admin&grant_type=password&scope=read&client_id=CLIENTID&client_secret=CLIENTSECRET"
Thanks to this post, I have tested JHipster UAA, alongside JHipster version 5 .
This command could be a working sample:
curl -X POST -v http://[server-ip]:9999/oauth/token -i
-H "Accept: application/json"
-H "Authorization: Basic aW50ZXJuYWw6aW50ZXJuYWw="
-d "username=admin&password=admin&grant_type=client_credentials&scope=web-app"
Important notice:
Username and password must be replaced with yours.
The BASE64 encoded value of your 'clientId + ":" + clientSecret' must be set in header.
In my case BASE64('internal:internal')='aW50ZXJuYWw6aW50ZXJuYWw='
https://www.base64encode.org/ can be used to encode your text.
Since you have put client Id and secret on message Header, no need to provide it on message body.
And this could be a sample output:
{
"access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY29wZSI6WyJ3ZWItYXBwIl0sImV4cCI6MTUzNTM2ODEyNiwiaWF0IjoxNTM1MzY2MzI2LCJqdGkiOiJiYjYwMWVkYS01NjUyLTQ5OTgtYWJkNS04YzYxZjA3Y2U1ODUiLCJjbGllbnRfaWQiOiJpbnRlcm5hbCJ9.lNqpfE7N6XJVFe9t7zPbwokU_zl4AFIAmQJZ_Hb2ok0vBpWrDMf3v6KgEEi5bN2iyRd0TQBelSIJothrsYHoTk0ZaeeK9BM97OJr4Uc8kLzn2Vp-xpBk8-n2PlwAKIRojoOxMnBp0nA2qjPieaPV2Fj1HETmK2gZ38lQcZ_KJLD-ug9AT9_N1E9SwRjt1yfZtd64IJZOQGqcZ05VCAj54jxH9lyvX-_1NY2Iq2aA5-cGbOftmv0sUjF15EiTGps6YtFUrJqKs8PmDofMImyqjAwB3yNObpg7c6PbeCXWYLAir5IOFdueTys3cLLyrhE78GJ3OiKSAA128nZSeUbiAg",
"token_type" : "bearer",
"expires_in" : 1799,
"scope" : "web-app",
"iat" : 1535366326,
"jti" : "bb601eda-5652-4998-abd5-8c61f07ce585"
* Connection #0 to host [server-ip] left intact
}
Using the default generated jhipster app (3.5.0), this is how you would curl a token for the admin user:
> curl -X POST -u jhipsterapp:my-secret-token-to-change-in-production -i -H 'Accept:application/json' http://localhost:8080/oauth/token -d "username=admin&password=admin&grant_type=password&scope=read%20write"
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-Application-Context: jhipster:swagger,dev:8080
Cache-Control: no-store
Pragma: no-cache
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 22 Jul 2016 13:09:38 GMT
{
"access_token" : "4a1ae413-5cd7-46e9-8a33-31698218d43e",
"token_type" : "bearer",
"refresh_token" : "537f231c-e6e0-4499-bbd8-9580eee02f79",
"expires_in" : 1799,
"scope" : "read write"
}
Note: here is my .yo-rc.json:
{
"generator-jhipster": {
"jhipsterVersion": "3.5.0",
"baseName": "jhipster",
"packageName": "com.mycompany.myapp",
"packageFolder": "com/mycompany/myapp",
"serverPort": "8080",
"authenticationType": "oauth2",
"hibernateCache": "ehcache",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "mysql",
"searchEngine": "no",
"buildTool": "maven",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"jhiPrefix": "jhi",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en"
]
}
}