-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auth: OAuth 1.0 #1004
Comments
i will be pending for this functionality |
I also need OAuth 1.0 functionality before I can replace Postman |
+1 |
You might now use a collection pre-script for that, here is some code to get you started:
Run once in the folder where is your collection |
I got oauth1.0a running with Adobe Commerce / Magento 2. I use a env variable Then this works: const OAuth = require('oauth-1.0a');
const CryptoJS = require('crypto-js');
// Get the signature method from the environment or default to 'HMAC-SHA256'
const signatureMethod = bru.getEnvVar('signature_method') || 'HMAC-SHA256';
// Initialize OAuth1.0a with your credentials
const oauth = OAuth({
consumer: {
key: bru.getEnvVar('consumer_key'),
secret: bru.getEnvVar('consumer_secret')
},
signature_method: signatureMethod,
hash_function(base_string, key) {
return CryptoJS.HmacSHA256(base_string, key).toString(CryptoJS.enc.Base64);
}
});
// Replace {base_url} in req.url with the actual environment variable
console.log(bru.getEnvVar('base_url'));
let url = req.url.replace(/\{\{base_url\}\}/gi, bru.getEnvVar('base_url'));
console.log(url);
// Get request data
const requestData = {
url: url,
method: req.method,
//data: req.body ? req.body : {}, // Magento does not want to have the body in the signature data
};
// Add OAuth tokens
const token = {
key: bru.getEnvVar('access_token'),
secret: bru.getEnvVar('access_token_secret')
};
const authHeaders = oauth.toHeader(oauth.authorize(requestData, token));
console.log(authHeaders);
// Set the Authorization header using req.setHeader
req.setHeaders(authHeaders); As mentioned before a |
One issue I found is that if path variables are used in the url it's not replaced in the pre-script. |
@cmuench What is "a collection pre-script"? Does it work with the desktop app or just from the CLI? How? Where should I put it? How does it connect to a request? |
In the collection settings |
Achso... you are a gentleman, @cmuench! |
likewise. 30 minutes later...
|
Hey, people waiting for this feature, would you please take a look at #2989 ? I'd appreciate if you tested your usecases against what's available at that branch, especially if you have some real-life oauth1 service utilizing |
Hey guys, |
@yesm1ke Starting off my pre-script code should get you working faster... |
I adjusted the @cmuench code so that it keeps the headers from the original request, making an assign with the ones from oauth, so it still passes on what we put in the header section of Bruno. Delete everything after the line that contains
|
Parent Issue: #119
Support OAuth 1.0
The text was updated successfully, but these errors were encountered: