Angular JS - Establishing a Connection to Woocommerce OAuth v1

I'm having trouble authenticating myself with the rest service.

I attempted to use this library to generate all the necessary parameters as mentioned here, and I constructed the request like this:

$scope.oauth = new OAuth({
    consumer: {
        public: 'ck_d34c32d9c7f6fc1ddb6e85879fc4de89',
        secret: 'cs_1867e5e54ce054dde7cf463ad78ee6f9'
    },
    signature_method: 'HMAC-SHA1'
});

var request_data = {
        url: 'http://belfiore.link-me.it/wc-api/v1/orders',
        method: 'GET',
    }
    $scope.data = $scope.oauth.authorize(request_data);

    $scope.url = rawurlencode(request_data.url) + "&" + 
                "oauth_consumer_key"+"%3D"+rawurlencode($scope.data.oauth_consumer_key)+
                "%26"+"oauth_nonce"+"%3D"+rawurlencode($scope.data.oauth_nonce)+
                "%26"+"oauth_signature_method"+"%3D"+rawurlencode($scope.data.oauth_signature_method)+
                "%26"+"oauth_timestamp"+"%3D"+rawurlencode($scope.data.oauth_timestamp)+
                "%26"+"oauth_signature"+"%3D"+rawurlencode($scope.data.oauth_signature);

    var call = $http.get($scope.url);
    call.success(function(res) {
        console.log(res);
    });
    call.error(function(res) {
        console.log(res);
    });

However, I keep receiving this response:


"Cannot GET /http%3A%2F%2Fbelfiore.link-me.it%2Fwc-api%2Fv1%2Forders&oauth_consumer_key%3Dck_d34c32d9c7f6fc1ddb6e85879fc4de89%26oauth_nonce%3DwkeLtFTh6WAuxDQGqnpzxAWYOQiHnHSr%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D10%26oauth_signature%3DjFhPbKHnvMEvYf20w1vN3TAV5Ds%3D"

Can anyone provide assistance? I have searched online for tutorials or an Angular-ready OAuth1 library but have not found anything...

Thank you in advance

Answer №1

I am the creator of the oauth-1.0a library.

Although I have not experimented with angularjs yet, a quick look suggests using the following code snippet:

$http({
    url: request_data.url,
    method: request_data.method,
    params: $scope.oauth.authorize(request_data)
});

Answer №2

While rawurlencode is a PHP function, it is recommended to use the JavaScript function encodeURIComponent as a replacement.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for Keeping Sub Menu Visible Without Having to Click

I am working on an HTML navigation menu that opens submenus on click like this... $("#nav_evnavmenu > li > a").click(function () { // bind onclick if ($(this).parent().hasClass('selected')) { $("#nav_evnavmenu .selected div div ...

What are the steps to implementing PNG masking using PixiJS?

I am currently working on incorporating a png sprite as a mask for another layer. I found a demo on the pixi.js official website and created this fiddle: https://jsfiddle.net/raphadko/ukc1rwrc/ The code snippet below is what I am using for the masking fu ...

Explain the mechanics of the calculator code operating by inputting numerical values in a string format

Recently, I attempted to create a calculator in JavaScript and encountered a requirement to place the button values within single quotes as if they were strings. It's fascinating how these string values can work alongside operators to produce the desi ...

Completing the regex properly

When using my editor, I am able to paste a video URL which is then converted by regex into an embed code. The URL in the WYSIWYG-editor looks like this: Once converted, the output HTML appears as: <p>http://emedia.is.ed.ac.uk:8080/JW/wsconfig.xml& ...

Combine the object with TypeScript

Within my Angular application, the data is structured as follows: forEachArrayOne = [ { id: 1, name: "userOne" }, { id: 2, name: "userTwo" }, { id: 3, name: "userThree" } ] forEachArrayTwo = [ { id: 1, name: "userFour" }, { id: ...

What is the best way to retrieve the items stored within the array generated by a JavaScript function?

This particular function is responsible for calling a PHP script that outputs JSON data. It then iterates through the JSON object, creates a new object, and adds this new object to an array which is ultimately returned by the function. function getTestQues ...

Why does JavaScript not wait for the completion of forEach and instead executes the next line immediately?

While creating my api in nodejs and attempting to push the mongoose return count to a newly created array, it does not wait for the forEach loop to finish before executing json.res() and returning a null response. However, when I use setTimeout(), the re ...

What is the best way to evaluate a sequence of actions and their outcomes?

Recently, I've dived into the world of writing automated tests for a React application. Along the way, I encountered some intriguing questions about the best approach to testing a series of interactions within the app. Let's imagine a scenario w ...

"Upon submitting a form in React JS, the components will automatically trigger a

Within my application, there is a Mobx storage in conjunction with a modal window component. The form within the modal window allows me to collect all the properties and push them into an array named 'cart' within the storage as an object. Take a ...

Counting down in JavaScript until the desired MySQL datetime format is reached

I'm trying to display a countdown of hours and minutes to a date pulled from a MySQL database in the format 2010-09-24 11:30:12. I am not well-versed with dates in JavaScript, so any guidance would be greatly appreciated. Thank you. ...

The image will remain static and will not alternate between hidden and visible states

I am facing a challenge trying to toggle an image between 'hidden' and 'show' My approach is influenced by the post on How to create a hidden <img> in JavaScript? I have implemented two different buttons, one using html and the ...

Potential 'undefined' object detected in Vuex mutation using TypeScript

Currently, I am diving into learning Vue.js alongside Vuex and TypeScript. While working on my application, I encountered an error stating "Object is possibly 'undefined'" within the Vuex Store. The error specifically arises in the "newCard" mut ...

Tips for including a variable in the src attribute

I am facing an issue with the img tag <img src='http://...../{{element}}'/> and encountering this error message: /%7B%7element%7D%7D 404 (Not Found) Can anyone guide me on how to add a variable to the src attribute in angular.js? ...

Exploring the Power of Angular Toastr Callback Functions

Hey there! I'm currently working with Angular Toastr to display messages on my screen. I have a setup where only two messages can be open at the same time - one for errors and another for warnings. These messages are persistent and require user intera ...

Executing multiple HTTP requests simultaneously in groups using an asynchronous for loop for each individual request

I'm currently working on running multiple requests simultaneously in batches to an API using an array of keywords. Read Denis Fatkhudinov's article for more insights. The issue I'm facing involves rerunning the request for each keyword with ...

Count the occurrences of x.status being equal to 10 in AngularJS

I have 3 different statuses: 10, 20, and 30. I am trying to determine how many times x.status equals 10 and display that count. My initial approach was something like this: count="x.status" where="x.status == 10" Count: {{value}} <!DOCTYPE html> ...

Guide to using Angular $resource to pass query parameter array

My goal is to implement a feature that allows users to be searched based on multiple tags (an array of tags) using the specified structure: GET '/tags/users?tag[]=test&tag[]=sample' I have managed to make this work on my node server and hav ...

"Implementing a full page refresh when interacting with a map using

Here is an example of how I display a map on the entire page: <div id="map_canvas"> </div> UPDATE 2: I have successfully displayed a menu on the map, but there is a problem. When I click on the button, the menu appears briefly and then disapp ...

What could be causing me to receive two responses from this AJAX request?

Can someone shed light on why I am receiving a double success response from this AJAX call using Bootstrap modals? Instead of getting test, I am seeing testtest. After inspecting the console, it appears that only one request is being made and I've c ...

pagination functionality incorporated into element ui tables

Issue with Element UI: when a checkbox is selected and the page is changed, the selected rows' checkboxes are removed. I need to retain the selection items while paging so that users can select items from multiple pages without losing the selections f ...