question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access Token Exchange always returns 'Error: Signature not authentic!'

See original GitHub issue

I have been pulling my hair out for the past day trying to figure out where I am going wrong, but when i try to get my app setup for public use I just get errors when I try to finish doing the auth, see the relevant code below…

router.get('/install', function(req, res, next) {
    shop = req.param('shop');
    Shopify = new shopifyAPI({
        shop: shop, // MYSHOP.myshopify.com
        shopify_api_key: apikey, // Your API key
        shopify_shared_secret: sharedkey, // Your Shared Secret
        shopify_scope: 'read_orders,read_products,read_customers',
        redirect_uri: appurl + '/finish_auth',
        nonce: n() // you must provide a randomly selected value unique for each authorization request
    });
    writeConfigData(shop, Shopify.config); //writes the config to firebase, worried the config was wrong
    var auth_url = Shopify.buildAuthURL();
    res.redirect(auth_url);
});

router.get('/finish_auth', function(req, res){
    var theshop = req.param('shop').replace(/\./g, "_"); //this is just to find the saved shopconfig in firebase
    database.ref('configs/' + theshop).once('value').then(function(snapshot) {
        var config = snapshot.val();
        var Shopify = new shopifyAPI(config), // You need to pass in your config here
            query_params = req.query;
        Shopify.exchange_temporary_token(query_params, function (err, data) {
            // This will return successful if the request was authentic from Shopify
            // Otherwise err will be non-null.
            // The module will automatically update your config with the new access token
            // It is also available here as data['access_token']
            console.log("HERE IS THE EXCHANGE: " + err + data);
        });
    });

});

The current Docs are a little fuzzy with is_valid_signature and the way that Shopify uses hmac now instead, I have tried about a thousand different workarounds but always get that same error… I am starting to think it might actually be Shopify.

Any help with this issue would be awesome

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:9

github_iconTop GitHub Comments

2reactions
lfernando-silvacommented, Jun 3, 2018

for me, the @itjustwerks solution worked.

const nonce = require('nonce')();

//...config shopify object stuff
nonce: nonce().toString()


1reaction
itjustwerkscommented, Feb 17, 2017

@MasterDover and @mayconfsousa … I’m working on setting up my first public Shopify app, and had the same issue as you with this package. It seems the issue is coming from the use of nonce function in the config parameters. If you generate your nonce before defining your Shopify var, it should work for ya!

var nonceVal = n();
var Shopify = new shopifyAPI({
    shop: 'MYSHOP',
   ...
   nonce: nonceVal.toString()
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Invalid Token Errors - Auth0
Parsing an HS256-Signed ID Token Without an access token. Error Message: The ID token cannot be validated because it was signed using the...
Read more >
Why jwt.io website is giving an error for validating a token?
TOKEN SIGNING PUBLIC KEY (JWK FORMAT). This is the item in the keyset that matches the kid field from the JWT header.
Read more >
Possible Errors - OAuth 2.0 Simplified
If the client ID is not recognized, the authorization server will not redirect the user. Instead, it may display a message describing the ......
Read more >
The Authorization Code grant (in excruciating detail) Part 2 of 2
If it all checks out, mints a time bound access token, cryptographically signing it, and returns it to the OAuth token exchange component....
Read more >
How to get an access token with Authorization Code Grant
Invalid authentication request : The response type is not supported indicates that the application attempting to use Authorization Code Grant authentication is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found