Authy API Webhook - Invalid Signature response - twilio

I'm trying to create a Webhook according to the documentation page:
https://www.twilio.com/docs/authy/api/webhooks
My curl call looks like this:
curl -X POST "https://api.authy.com/dashboard/json/application/webhooks" \
-d name="gridzdev_test" \
-d app_api_key="7N0..." \
-d access_key="4za..." \
-d url="https://some-random-string.ngrok.io/api/2fa/webhook" \
-d events="user_added" \
-H "X-Authy-Signature-Nonce: FiNwPdKZci4l3LEn" \
-H "X-Authy-Signature: feYEERfOSoWCB3ml5cnZFWs5xhc1sPeiWguhlJnokKQ="
Unfortunately, the response I receive is not what I expect:
{"message":"Invalid signature.","success":false,"error_code":"60000"}
The PHP code I'm using to generate signature:
public function handle() {
$url = 'https://api.authy.com/dashboard/json/application/webhooks';
$http_method = 'POST';
$params = 'id=53';
$nonce = 'FiNwPdKZci4l3LEn';
$signing_key = 'pr...';
$data = $nonce . '|' . $http_method . '|' . $url . '|' . $params;
$digest = hash_hmac('sha256', $data, $signing_key, true); // TODO tried with binary = false, but no joy
$digest_in_base64 = base64_encode($digest);
$this->info("nonce = $nonce");
$this->info("signature = $digest_in_base64");
}

Related

Save curl response in a variable in Jenkins declarative pipeline

I have a Jenkins decalarative pipeline where I am calling some URL via cURL which is returning JSON response. How to catch that JSON in a variable?
Have tried the below code but it's returning entire thing with path and command along with the response
environment {
token = bat(returnStdout: true, script: 'curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\\"username\\" : \\"user\\",\\"password\\" : \\"pwd\\"}"').trim()
}
JSON response
C:\ProgramData\Jenkins\.jenkins\workspace\publish-api>curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\"username\" : \"ap-1\",\"password\" : \"Ap5\"}"
{
"access_token": "axxxx-5ca2-48eb-9eb3-173c44a811",
"token_type": "bearer",
"redirectUrl": "/home/"
}
You can use the readJson method to get to your wished result. You don't necesseraly have to call it in your environment-block.
stage('Curl') {
steps {
script {
def cUrlResponse = bat(returnStdout: true, script: '#curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\\"${env.username}\\" : \\"user\\",\\"${env.password}\\" : \\"pwd\\"}"').trim()
def responseJson = readJSON text: cUrlResponse
def accessToken = responseJson.access_token
def tokenType = responseJson.token_type
// do other stuff with the variables
}
}
}
To exclude the curl command from the output, add # in front of the script as stated in the documentation.

Jenkins pipeline: passing in data variable as string into curl command

So I'm trying to pass in a string (data) into this sendSlackMessage function but it's not going into the curl command correctly. data is being passed in from my jenkinsfile.
It's working fine in the echo command though.
Can someone tell me what I'm doing wrong?
data = """{'channel': '#mychannel','username': 'jenkins-bot','icon_emoji': ':lol:','text': 'HERERERERE (<$BUILD_URL|Open>)','attachments': [['color': '#36a64f','fields': ['title': 'UPDATING INFOR','value': 'HELLOWORLD','short': 'true']]]}"""
void sendSlackMessage(String data) {
this.steps.sh(returnStdout: true, script: "echo hello world ${data} hello world again")
this.steps.sh(returnStdout: true, script: "curl -X POST -H 'Content-type: application/json' --data '${data}' https://hooks.slack.com/services/T12345671/sdfsdfsdf/sdf7sdf7gsdf")
}
Please try the below implementation
data = """{'channel': '#mychannel','username': 'jenkins-bot','icon_emoji': ':lol:','text': 'HERERERERE (<$BUILD_URL|Open>)','attachments': [['color': '#36a64f','fields': ['title': 'UPDATING INFOR','value': 'HELLOWORLD','short': 'true']]]}"""
void sendSlackMessage(String data) {
List curlCommand = []
curlCommand.add('curl -X POST -H')
curlCommand.add('\'Content-type: application/json\'')
curlCommand.add('--data')
curlCommand.add(data) // Maybe you have to see if you see to add a single quote here and escape it
curlCommand.add('https://hooks.slack.com/services/T12345671')
sh (
returnStdout: true,
script: curlCommand.join(" "),
label: "send slack message"
)
}

Not able to construct proper header for groovy function Get request

Writing my first function here for Groovy native lib and running into an issue. A method to get Github Labels for pull-requests. #param github_token String token with permission to access and read PR information.
getLabelsPerPullRequest.groovy: 19: expecting '}', found ':' # line 19, column 28. 'Authorization': 'token '+ github_token, ^
Here is my function
import groovy.json.JsonSlurper
def getLabelsPerPullRequest(String github_token) {
def labels
def scmHead = jenkins.scm.api.SCMHead.HeadByItem.findHead(currentBuild.rawBuild.getParent())
def repo = scmHead.getSourceRepo()
def prId = scmHead.getId()
if(github_token && github_token != null) {
// Set the call headers with Oauth token.
def headers = "{'Authorization': 'token '+ ${github_token},'Accept': 'application/vnd.github.v3+json'}"
// Construct request number URL in Github
def pr_url = "https://github.optum.com/api/v3/repos/SOP-Bot/${repo}/pulls/${prNbr}"
def json = sh(
script: "curl -X Get ${pr_url} -H ${headers}",
returnStdout: true
)
def prInfo = JsonOutput.toJson(text: json)
labels = prInfo.labels
}
return labels
}
Each header needs to be a separate -H argument. You can do something like this. I added -s to curl because you probably don't want the extra progress output but it may not actually be an issue.
def headers = [
"-H 'Authorization: token ${gitub_token}'",
"-H 'Accept: application/vnd.github.v3+json'"
]
...
def json = sh(
script: "curl -s -X GET ${headers.join(' ')} '${pr_url}'",
returnStdout: true
)

How to get all chats in website using zendesk chat api

There is any way to get all chats from zendesk to website.
I am using zendesk api for get all chats:
curl https://www.zopim.com/api/v2/chats \ -v -u {email_address}:{password}
Here Is my code :
public function getChat_messages(){
$sUrl = "https://www.zopim.com/api/v2/chats";
$authorization = "Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0";
$key= "-v -u email:password";
if (is_resource($rCh = curl_init($sUrl))) {
curl_setopt($rCh, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0',
'-v -u email:password',
));
curl_setopt($rCh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCh, CURLOPT_TIMEOUT, 3);
$arrResult = curl_exec($rCh);
$arrResult = explode("\n", $arrResult);
$response = curl_exec($rCh);
$err = curl_error($rCh);
curl_close($rCh);
}
print_r($response);
}
Help will be appreciated..
Thanks.. :)
You did well but there is a little mistake.
$sUrl = "https://www.{your_domain_name}.com/api/v2/chats";
You just copy and paste the line that is why you are getting error.
zopim is not your domain name use your domain name instead of zopim

Flutter- how to post https in this format?

I want to send post request in Dart.
curl looks like this.
curl -X POST "https://api-us.faceplusplus.com/facepp/v3/search" \
-F "api_key=<api_key>" \
-F "api_secret=<api_secret>" \
-F "face_token=c2fc0ad7c8da3af5a34b9c70ff764da0" \
-F "outer_id=facesetid"
I tried like this but error response says
MISSING_ARGUMENTS: api_key
final String apiKey = API_KEY;
final String apiSecret = API_SECRET;
final String faceToken = FACE_TOKEN;
final String outerId = OUTER_ID;
final data = jsonEncode({
'api_key': apiKey,
'api_secret': apiSecret,
'face_token': faceToken,
'outer_id': outerId
});
final http.Response request = await http.post(
'https://api-us.faceplusplus.com/facepp/v3/search',
body: data,
);
final String response = request.body;
final result = json.decode(response);
print(response);
print('------------------------');
print(result);
What am I missing?
How can I post this correctly?
From man curl
-F, --form <name=content>
(HTTP) This lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data
https://pub.dartlang.org/documentation/http/latest/http/MultipartRequest-class.html
var uri = Uri.parse("http://pub.dartlang.org/packages/create");
var request = new http.MultipartRequest("POST", url);
request.fields['user'] = 'nweiz#google.com';
request.files.add(new http.MultipartFile.fromFile(
'package',
new File('build/package.tar.gz'),
contentType: new MediaType('application', 'x-tar'));
request.send().then((response) {
if (response.statusCode == 200) print("Uploaded!");
});

Resources