bettiolo / oauth-signature-js

JavaScript OAuth 1.0a signature generator (RFC 5849) for node and the browser
https://www.npmjs.com/package/oauth-signature
BSD 3-Clause "New" or "Revised" License
232 stars 71 forks source link

uri-js dependency is failing on react-native #27

Open mixophrygian opened 8 years ago

mixophrygian commented 8 years ago

Hi, thanks for this fantastic package. I was using oauth-signature with great success on react-native until I upgraded from 0.18 to 0.27 (now 0.28) in preparation for iOS 10. After upgrading the oauth-signature generate method fails at -> uri-js/build/schemes/http.js with the error undefined is not an object (evaluating 'URI.SCHEMES'). It's not clear whether uri-js is still being maintained. Any suggestions would be appreciated. Again, great package and I hope to continue using it.

bettiolo commented 8 years ago

Thanks for reporting, I am going to look into it. Have you got a react-native code example to share?

bettiolo commented 8 years ago

You may look into opening an issue with uri-js as well?

mixophrygian commented 8 years ago

Yes, I have opened one with that module but I'm unsure if it's still being maintained. https://github.com/garycourt/uri-js/issues/14

mixophrygian commented 8 years ago

package.json:

{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node_modules/react-native/packager/packager.sh"
  },
  "dependencies": {
    "lodash": "4.6.1",
    "oauth-signature": "1.3.1",
    "querystring": "0.2.0",
    "react": "^15.1.0",
    "react-native": "^0.28.0",
    "react-native-communications": "^1.0.1"
  }
}

yelp_api.js (worked in react-native 0.18!)

import qs from 'querystring';
import _ from 'lodash';
import  nonce from './nonce.js';
import timestamp from './timestamp.js';
import config from './config.js';
import oauthSignature from 'oauth-signature';

function request_yelp(get_location) {

    const httpMethod = 'GET';

    const url = 'https://api.yelp.com/v2/search';

    let default_parameters = {
        term: 'pizza',
        sort: '1',
    };

     function locationOrCoords(get_location){
       var result = get_location.split(',').map(Number);
       if(result[1]) { //contains a comma and therefore is lat / long
           default_parameters.ll = get_location; 
       } else { //is a zip or a location name
           default_parameters.location = get_location;
        };
    };

    locationOrCoords(get_location);

    const required_parameters = {
        oauth_consumer_key : config.key, 
        oauth_nonce : nonce(16),
        oauth_signature_method : 'HMAC-SHA1',
        oauth_timestamp : timestamp(),
        oauth_token : config.token,
        oauth_version : '1.0'
    };

    let parameters = _.assign(default_parameters, required_parameters);;

    const consumerSecret = config.consumerSecret;
    const tokenSecret = config.tokenSecret;
    const signature = oauthSignature.generate(httpMethod, url, parameters, consumerSecret, tokenSecret, { encodeSignature: false});

    parameters.oauth_signature = signature;

    const paramURL = qs.stringify(parameters);
    const apiURL = url+'?'+ paramURL;

    console.log(apiURL);    
    return apiURL;

};
exports.request_yelp = request_yelp;

On both the simulator alone (using react-native run-ios) and Xcode, the error: undefined is not an object (evaluating 'URI.SCHEMES')

stack:

<unknown>
http.js:4

loadModuleImplementation
require.js122

guardedLoadModule
require.js:65

_require
require.js49

<unknown>
schemes.js:1

loadModuleImplementation
require.js:122

guardedLoadModule
require.js:65

<unknown>
uri.js:497

loadModuleImplementation
require.js:122

guardedLoadModule
require.js:58

_require
require.js:49

parseInNode
oauth-signature.js:101

get
oauth-signature.js:65

SignatureBaseString
oauth-signature.js:24

generate
oauth-signature.js:11

request_yelp
yelp_api.js:43

etc.
jojonarte commented 7 years ago

I'm also having the same issue as well.

http://screencast.com/t/uyfrj7my42Y

bettiolo commented 6 years ago

Can you confirm that this is fixed with the latest version released on npm?