Skip to content
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

prerequest script #27

Closed
johncagnina opened this issue Apr 20, 2020 · 2 comments
Closed

prerequest script #27

johncagnina opened this issue Apr 20, 2020 · 2 comments

Comments

@johncagnina
Copy link

Hi @geral2 ,

Is it possible to run a prerequest script. I need to get an auth header.

John

@geral2
Copy link
Owner

geral2 commented Apr 20, 2020

Hi,

Do you have any code, how we can get the headers in a prerequest?

@johncagnina
Copy link
Author

See postman file and let me know

"info": {
"_postman_id": "f06e8df0-1a88-4c7b-8b90-ecf353c23a6b",
"name": "",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "newnotification",
"event": [
{
"listen": "prerequest",
"script": {
"id": "1c718015-8f7c-490d-861f-abf26bb7d94d",
"exec": [
"function getAuthHeader(resourceUri, keyName, key) {\r",
"\r",
" var d = new Date();\r",
" var sinceEpoch = Math.round(d.getTime() / 1000);\r",
" var expiry = (sinceEpoch + 3600);\r",
" var stringToSign = encodeURIComponent(resourceUri) + '\n' + expiry;\r",
" var hash = CryptoJS.HmacSHA256(stringToSign, key);\r",
" var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);\r",
" var sasToken = 'SharedAccessSignature sr=' + encodeURIComponent(resourceUri) + '&sig=' + encodeURIComponent(hashInBase64) + '&se=' + expiry + '&skn=' + keyName;\r",
" console.log(sasToken);\r",
" \r",
"\r",
" return sasToken;\r",
"}\r",
"postman.setEnvironmentVariable('azure-authorization',getAuthHeader(request.url,"KeyName", "Key"));\r",
"postman.setEnvironmentVariable('current-date',new Date().toUTCString());"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "{{azure-authorization}}",
"type": "text"
},
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "ServiceBusNotification-Format",
"value": "gcm",
"type": "text"
},
{
"key": "ServiceBusNotification-Tags",
"value": "veelead1",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{"data":{"gcm.notification.body":"Hello the push notification "}}"
},
"url": {
"raw": "https://xdnotification.servicebus.windows.net/xdnotihub/messages/?api-version=2015-01",
"protocol": "https",
"host": [
"xdnotificationpoweriq",
"servicebus",
"windows",
"net"
],
"path": [
"xdnotihub",
"messages",
""
],
"query": [
{
"key": "api-version",
"value": "2015-01"
},
{
"key": "",
"value": null,
"disabled": true
}
]
},
"description": ""
},
"response": []
}
],
"protocolProfileBehavior": {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants