I am trying to get an acces token from magento by using OAuth1. when i send the array bellow i get this error
oauth_problem=%22oauth_consumer_key%22+is+required.+Enter+and+try+again%2C+%22oauth_signature%22+is+required.+Enter+and+try+again%2C+%22oauth_signature_method%22+is+required.+Enter+and+try+again%2C+%22oauth_nonce%22+is+required.+Enter+and+try+again%2C+%22oauth_timestamp%22+is+required.+Enter+and+try+again
I am pretty new to the magento api and cant figure out what is wrong with my request. below is a vardump of the data getting send. if you see the problem please let me know.
array(5) { ["Authorization"]=> string(317) "OAuth oauth_consumer_key="hqq7epm3vew3jflzd78aqhg48p9mki3k", oauth_callback="THIS IS NORMALLY FILLED", oauth_nonce="WjEzGaS3egCnoZ6SLMUQ8fL5ljmf9qVw", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1667217588", oauth_version="1.0", oauth_signature="lZvRLjl06Ta2yLWeMB2w5FO2jQQ%3D"" ["Content-type"]=> string(47) "Content-type: application/x-www-form-urlencoded" ["Host"]=> string(27) "Host:THIS IS NORMALLY FILLED" ["Connection"]=> string(17) "Connection: close" ["Content-length"]=> string(17) "Content-length: 0" }
Related
I'm using the dynamics CRM REST API to create projects, and manage some actions on Microsoft Projects online.
We're using labels, which we can apply to tasks, to signify various things.
Via the API I can read labels, and I can read and write the labels that have been assigned to each task (msdyn_projecttask).
The bit I haven't succeeded with is creating an API call which will change the text of a label from the default (Pink, Red, Yellow etc.) to something more useful.
Currently I'm having to manually edit the label text via the Project User Interface (e.g. see below).
Once I've renamed the label, when I fetch them via the API I can see the changed text, but I can't figure out a way to change it via the API.
I'm able to fetch the project labels via
GET https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels?$filter=_msdyn_projectid_value%20eq%20%27{projectId}%27
(where {projectId} is the msydn_projectid of my project)
Which returns data like:
{
"#odata.context":"https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/$metadata#msdyn_projectlabels",
"value":[
{
"#odata.etag":"W/\"21783358\"",
"_owningbusinessunit_value":".....",
"statecode":0,
"msdyn_colorindex":192350000,
"statuscode":1,
"_createdby_value":"....",
"_ownerid_value":".....",
"_owningteam_value":".....",
"modifiedon":"2022-11-02T13:32:26Z",
"_modifiedby_value":"....",
"versionnumber":21783358,
"_msdyn_projectid_value":".....",
"createdon":"2022-11-02T13:32:26Z",
"msdyn_projectlabelid":"625eb1b2.....",
"_owninguser_value":null,
"overriddencreatedon":null,
"importsequencenumber":null,
"_modifiedonbehalfby_value":null,
"msdyn_projectlabeltext": "Label One",
"utcconversiontimezonecode":null,
"_createdonbehalfby_value":null,
"timezoneruleversionnumber":null
},
....
]
}
I've tried:
PATCH https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels({labelId}})
(where {labelId} is one of the msdyn_projectlabelid values returned above)
headers: [
"If-Match: *",
"OData-MaxVersion: 4.0",
"OData-Version: 4.0",
"Accept: application/json",
"Authorization: ...",
"Content-Type: application/json; charset=utf-8"
]
body: {
"msdyn_projectlabeltext": "Test Label 1"
}
But it fails and says:
"We\u2019re sorry. You cannot directly do 'Update' operation to 'msdyn_projectlabel'. Try editing it through the Resource editing UI via Project."
And I've tried:
PATCH https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels
headers: [
"If-Match: *",
"OData-MaxVersion: 4.0",
"OData-Version: 4.0",
"Accept: application/json",
"Authorization: ...",
"Content-Type: application/json; charset=utf-8"
]
body: {
"msdyn_projectlabeltext": "Test Label 1"
"msdyn_projectlabelid#odata.bind": "/msdyn_projectlabels({labelId})"
}
Which fails, saying:
"The requested resource does not support http method 'PATCH'."
Also tried:
PUT https://orgXYZABC.api.crm4.dynamics.com/api/data/v9.1/msdyn_projectlabels({labelId})/msdyn_projectlabeltext
headers: [
"OData-MaxVersion: 4.0",
"OData-Version: 4.0",
"Accept: application/json",
"Authorization: ...",
"Content-Type: application/json; charset=utf-8"
]
body: {
"value": "Test Label 1"
}
Which fails with the same error as above.
There doesn't seem to be any documentation for this anywhere, if you google "msdyn_projectlabel" or "msdyn_projectlabels" (in quotes) you don't get a single result!
Anyone out there have any knowledge on whether this is possible / how to succeed?
I am trying to build a gnome shell extension (using gjs) that I need to communicate with an external REST API. In order to do so, I need to accompany my requests with the header: Authorization: Bearer <token> and with a Content-Type: application/json.
I have looked all over for questions like this and I did find some similar ones but none of them works. The documentation is not helpful at all, and, if anything, it has only confused me more.
With curl I could send that request as follows:
curl -X GET -H "Authorization: Bearer <token>" -H "Content-Type: application/json" <url>
So far, I have only created extensions that send simple GET requests with no headers. Then I would do the following:
const Soup = imports.gi.Soup;
let soupSyncSession = new Soup.SessionSync();
let message = Soup.Message.new('GET', url);
let responseCode = soupSyncSession.send_message(message);
let res;
if(responseCode == 200) {
res = JSON.parse(message['response-body'].data);
}
Any idea on how I can add the headers? Any help would be appreciated!
EDIT:
By using #ptomato's answer I ended up using the following code:
function send_request(url, type='GET') {
let message = Soup.Message.new(type, url);
message.request_headers.append(
'Authorization',
`Bearer ${token}`
)
message.request_headers.set_content_type("application/json", null);
let responseCode = soupSyncSession.send_message(message);
let out;
if(responseCode == 200) {
try {
out = JSON.parse(message['response-body'].data);
} catch(error) {
log(error);
}
}
return out;
}
Initial Comment:
So, I managed to find a workaround but it is not efficient and so I will not mark it as the accepted answer. If anyone knows how to answer my question using Soup, please answer!
My workaround involves using the imports.misc.util file which includes the function spawnCommandLine for executing shell commands. So, I used curl in order to download the json to a file (the path variable below):
Util.spawnCommandLine(`/usr/bin/curl -X ${type} -H "Authorization: Bearer ${token}" -H "Content-Type: application/json" ${url} -o ${path}`);
and then I read the contents by using the following:
let text = GLib.file_get_contents(path)[1];
let json_result = JSON.parse(text);
This is not efficient at all and there should be an easier way around. But, until that is found, I hope this will be able to help someone else.
message.request_headers is a Soup.MessageHeaders object to which you can append() the authorization and content type headers.
Additionally there is a convenient set_content_type() method for the content type header specifically.
Generating the request to list the vpc details with IAM token which is kept in authorization header - The request has been generated from React App -
https://urls.cloud.ibm.com/v1/vpcs?version=2019-08-06&generation=1
Configuration
config = {
headers: {
"Authorization": "Bearer lmtmlmlm",
"Access-Control-Allow-Origin": "*"
}
}
The request was failed during the pre-flight request, it seems that the browser request headers are asking the server for permissions to make the actual request.
Can you suggest to overcome the problem.
The instructions here worked well for me: https://cloud.ibm.com/docs/vpc-on-classic?topic=vpc-on-classic-creating-a-vpc-using-the-rest-apis
I noticed you used the url: https://urls.cloud.ibm.com while these docs suggested https://us-south.iaas.cloud.ibm.com
rias_endpoint="https://us-south.iaas.cloud.ibm.com"
iam_token='Bearer zzzrandomstuff...eyJraWQiOiIyMDE5MDUxMyIsImFsZyI6IlJTMjU2In'
version="2019-05-31"
curl -X GET "$rias_endpoint/v1/vpcs?version=$version&generation=1" -H "Authorization: $iam_token"
I am trying to send a test notification using Firebase Cloud Messaging via Postman. I'm doing a POST to this url
https://fcm.googleapis.com/v1/projects/[my project name]/messages:send
The Authorization tab in Postman is set to No Auth and my Headers tab looks like this
Content-Type: application/json
Authorization: Bearer [server key]
[server key] is a newly generated server key in the 'Cloud Messaging' tab of my Firebase project's 'Settings' area. I keep getting this error in response.
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
Based on everything I can find, I'm using the right token, but it seems Google disagrees. What should I be sending as the Authorization header to get past this error?
Steps to get Authentication Bearer:
Got to Google OAuth Playground: https://developers.google.com/oauthplayground
In the "Input your own scopes" for FCM use this url: https://www.googleapis.com/auth/firebase.messaging
Tap Authorize API.
Pick correct user for authorisation and allow access.
In the Step 2: Exchange authorization code for tokens tap Exchange authorisation code for tokens.
Access token is your Bearer.
Steps to send FCM using Postman:
URL to send: https://fcm.googleapis.com/v1/projects/projectid-34543/messages:send
Request Type: POST
Headers: Content-Type -> application/json & Authorization -> Bearer
In the body section enter APS payload with the right device token.
Click send.
In case you want to use cURL, for a data-notification:
curl --location --request POST 'https://fcm.googleapis.com/v1/projects/your-project-id/messages:send' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your-access-token-*****-wqewe' \
--data-raw '{
"message": {
"token": "device-token-qwfqwee-***-qefwe",
"data": {
"Key1": "val1",
"Key2": "val2"
}
}
}'
You have to generate new access token in Postman.
First, ensure you have enabled FCM API in Google Developer Console.
Than go to Google Developer Console -> APIs & Services -> Credentials. Look at "OAuth 2.0 client IDs" section. There should be at least one item in list. Download it as json file.
In Postman open "Authorization" tab, select Type = "OAuth 2.0" than click "Get New Access Token". Dialog appears.
Fields:
Token Name - type what you want
Grant Type = Authorization Code
Callback URL = redirect_uris from downloaded json
Auth URL = auth_uri
Access Token URL = token_uri
Client ID = client_id
Client Secret = client_secret
Scope = "https://www.googleapis.com/auth/firebase.messaging"
State - leave empty
Client Authentication = default, Send As Basic Auth Header
Click "Request Token" and that's it.
The Bearer Token is the result of getting an OAuth access token with your firebase service account.
Get yourself a Firebase service account key.
Go to your firebase console > Settings > Service Accounts.
If your on Firebase Admin SDK generate new private key.
You use the service account key to authenticate yourself and get the bearer token.
Follow how to do that in Node, Python or Java here:
https://firebase.google.com/docs/cloud-messaging/auth-server.
So in Java you can get the token like this:
private static final String SCOPES = "https://www.googleapis.com/auth/firebase.messaging";
public static void main(String[] args) throws IOException {
System.out.println(getAccessToken());
}
private static String getAccessToken() throws IOException {
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream("service-account.json"))
.createScoped(Arrays.asList(SCOPES));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
And now you can finally send your test notification with FCM.
Postman code:
POST /v1/projects/[projectId]/messages:send HTTP/1.1
Host: fcm.googleapis.com
Content-Type: application/json
Authorization: Bearer access_token_you_just_got
{
"message":{
"token" : "token_from_firebase.messaging().getToken()_inside_browser",
"notification" : {
"body" : "This is an FCM notification message!",
"title" : "FCM Message"
}
}
}
To generate an for testing push notification, you can use Google Developers OAuth 2.0 Playground
You can even send a test Push Notification using Google Developers OAuth 2.0 Playground itself.
Or if you want can use Postman / Terminal (curl command) as well.
Please find the detailed steps here, which I wrote.
Note : Instead of "Project name" in the Endpoint, you have to use "Project ID". Steps for getting the Project ID is also mentioned in the above link.
You should use definitely use Google-OAuth2.0, which can be generated using described steps in the provided link.
you can find detailed steps here, which I answered for similar question.
Good morning, guys. I'm still new to Loopback, and have a feeling that I'm missing something, but not sure where and what to find, so advice would be helpful.
I have an app. I'm using local authentication with standard ACL.
I have few methods that open only for $owner, and few that open for $authenticated. I'm using few POST requests within the app to retrieve data, and every time I get 401 error. If use GET request, all I have to do is to include an access token id into the url like that url?access_token=jjkdfsjjkj334.
I have a feeling that there is a some sort similar of trick for POST requests.
Any help would be appreciated.
For the post request pass the access_token as the "Authorization" header in the respective post call.
request({url: url, json: true, headers: {'Authorization': 'access-token-value'}}, function (err, res, responseJson) {
console.log(responseJson);
});
You also specify other headers also, like Accept-type etc.
If you had a model called Test with the following ACL:
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
}
You should be able to make the following POST request:
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{}" "http://localhost:3000/api/Tests?access_token=cor7DDfUKoFSI6DzgCezQzoKFOuSmpLYzSF85xA8QXePkbFAGDKjjp7QwaVlP11B"
I always like to use the component explorer to test out what works and what doesn't. My guess is that something isn't set up properly in your ACL.