I worked on something similar today, I needed to set it up roughly as follows to have my request authenticated. (The code in the example is a bit more verbose for clarity)
import { HTTP } from '@ionic-native/http'
import OAuth from 'oauth-1.0a'
import CryptoJS from 'crypto-js/'
...
...
const consumer = {
key: YOUR_CONSUMER_KEY,
secret: YOUR_CONSUMER_SECRET
}
const token = {
key: YOUR_TOKEN_KEY,
secret: YOUR_TOKEN_SECRET
}
const hashFunction = (baseString, key) => {
return CryptoJS.HmacSHA1(baseString, key).toString(CryptoJS.enc.Base64)
}
const oauth = new OAuth(
{
consumer: {
key: consumer.key,
secret: consumer.secret
},
signature_method: 'HMAC-SHA1',
hash_function: hashFunction,
nonce_length: 6,
version: '1.0',
realm: ''
})
const request = {
url: endpoint,
method: 'GET',
params: {},
headers: {}
}
const oauthObject = oauth.authorize(request, token)
request.params = {
oauth_consumer_key: oauthObject.oauth_consumer_key,
oauth_nonce: oauthObject.oauth_nonce,
oauth_signature: oauthObject.oauth_signature,
oauth_signature_method: oauthObject.oauth_signature_method,
oauth_token: oauthObject.oauth_token,
oauth_version: oauthObject.oauth_version
}
request.headers = oauth.toHeader(oauthObject)
this.http
.get(request.url, request.params, request.headers)
.then(data => {
console.log(data.data) // data received by server
})
.catch(error => {
console.log(error.error) // error message as string
})
My signature kept being mismatched until I set up the request params (second argument for http.get) exactly like this.