I'm designing a Logic App in Azure, is there any way to make two HTTP request like this :
1. I'm calling my Identity Server 4 to get a new access token
2. I want to get the access token from the first request, put it to header and call .Net Core Api Endpoint with it?
Thanks
per my understanding, you want to know how to get access_token value from a JSON object which comes from response of get token http request .
I did a simple demo for you :
The details of the post request :
This is a simple request to get access token in Azure. the response will be :
{
"token_type": "Bearer",
"expires_in": "3600",
"ext_expires_in": "3600",
"expires_on": "1557995356",
"not_before": "1557991456",
"resource": "<-resource name->",
"access_token": "<-value of access token->"
}
As you can see this logic app is triggered by http request and it will do a post request to get an JSON object which contains an access_token. And finally it will return the access_token value in response .
So the key here is how to config so that we can get access_token value from the JSON response of step2 .
Let's open logic app code view, find "response" =>"body" and modify its value as : "#body('HTTP').access_token"
So that you can get the certain param from your JSON response of previous http request :
You can use the response of the first request by using Parsing JSON action.
Related
I have a HTTP POST set up in Postman that is working correctly. I also have an Azure Logic App that I need to invoke that HTTP POST instead of Postman. I see in Azure Logic Apps you can have an HTTP POST like so:
In Postman, it will give you the HTTP code snippet. I have tried different formats but I can't seem to get the POST to work like it does in Postman.
My Postman POST has authentication and form-data in the body which show up in the HTTP code snippet but when I paste that into the Body of the HTTP request in the logic app, the request fails.
Any ideas of what I'm doing wrong?
There's no importer ready to use. You need to convert whatever you have on Postman into this connector.
You should add headers (Authorization and Content Type)
Authorization: Bearer ey1230218312 (replace with valid token)
Content-Type : application/x-www-form-urlencoded
Body: name=abc&age=30
I was trying to capture webhook response when i am creating the task from inside podio dashboard but i can't receive any response in webhook.site
Used Postman, auth2.0 validation to create and validate the webhook
POST request for creation was
https://api.podio.com/hook/space/7026308/
Request body was
{
"url": "https://webhook.site/e664de7d-b571-42f0-8844-19723ae64caf",
"type": "task.create"
}
Response i get was
{
"hook_id": 17701094
}
Then In webhook.site i got this message
hook_id=17701094&code=51cf7340&type=hook.verify
Then i fire validate POST method from POSTMAN
My POST request was this
https://api.podio.com/hook/17701094/verify/validate
request body was
{
"code": "51cf7340"
}
Response was blank
Then i created a task inside from podio dashboard but i didn't receive any response in my webhook.site
Please provide solution for my problem
To verify a webhook, you need to call the /hook/{hook_id}/verify/validate API end-point with the hook_id and the code.
To do this, you need to be authenticated to the API, so you cannot just do a POST from Postman.
You should code for this in your webhook.site portal. If a POST request comes in with type=hook.verify, authenticate to the API and call /hook/{hook_id}/verify/validate.
For more, see the docs: https://developers.podio.com/doc/hooks/validate-hook-verification-215241
I want to use the Invoke Device Module API from Azure, where I want to send a payload using the API, which will be responsible for sending message from cloud to the module. I am following this article "https://learn.microsoft.com/en-us/rest/api/iothub/digitaltwinmodel/service/invokedevicemodulemethod"
I am using postman to execute this API, but I am getting the following response.
I have added 2 headers in postman 1] Authorization in this I have added a bearerToken and 2] content-type as application/json. I am giving a payload in the body section. Please let me know what could be wrong here, or if I need to configure it in some different way.
There is a double slash in URL http://azure-devices.net//twins. Can you please try with correct http://azure-devices.net/twins/
I figured out how it is done.
All we need to do is use the SAS Token in the authorization header instead of bearerToken and use the following body.
{
"methodName": "name_of_your_method",
"responseTimeoutInSeconds": 60,
"payload": {
"command": "your_message"}
}
The API URL is the following POST method
"https://fully-qualified-iothubname.azure-devices.net/twins/{deviceId}/modules/{moduleId}/methods?api-version=2019-07-01-preview"
Use the following command to generate SAS Token and FYI SAS Token expires after 1 hour of generation:
az iot hub generate-sas-token -n Ageye
This works perfectly fine and gives the following response:
{
"status": 200,
"payload": {
"status": "ok"
}
}
In the first step of my Logic App I call my API "Log On" endpoint passing in an Id/Password and receive a token.
How do I include that token in the header of all following requests?
Authorization: bearer TOKEN
I cannot work out how to read the response from the Log On and extract the token and then pass it in the header of all following calls.
Is this possible?
The way I do it is as follows.
1) Let us say your successful response from the log on HTTP action looks like below (sample taken from Authorize access to Azure Active Directory web applications using the OAuth 2.0 code grant flow)
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1THdqcHdBSk9NOW4tQSJ9.eyJhdWQiOiJodHRwczovL3NlcnZpY2UuY29udG9zby5jb20vIiwiaXNzIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvN2ZlODE0NDctZGE1Ny00Mzg1LWJlY2ItNmRlNTdmMjE0NzdlLyIsImlhdCI6MTM4ODQ0MDg2MywibmJmIjoxMzg4NDQwODYzLCJleHAiOjEzODg0NDQ3NjMsInZlciI6IjEuMCIsInRpZCI6IjdmZTgxNDQ3LWRhNTctNDM4NS1iZWNiLTZkZTU3ZjIxNDc3ZSIsIm9pZCI6IjY4Mzg5YWUyLTYyZmEtNGIxOC05MWZlLTUzZGQxMDlkNzRmNSIsInVwbiI6ImZyYW5rbUBjb250b3NvLmNvbSIsInVuaXF1ZV9uYW1lIjoiZnJhbmttQGNvbnRvc28uY29tIiwic3ViIjoiZGVOcUlqOUlPRTlQV0pXYkhzZnRYdDJFYWJQVmwwQ2o4UUFtZWZSTFY5OCIsImZhbWlseV9uYW1lIjoiTWlsbGVyIiwiZ2l2ZW5fbmFtZSI6IkZyYW5rIiwiYXBwaWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctODkwYS0yNzRhNzJhNzMwOWUiLCJhcHBpZGFjciI6IjAiLCJzY3AiOiJ1c2VyX2ltcGVyc29uYXRpb24iLCJhY3IiOiIxIn0.JZw8jC0gptZxVC-7l5sFkdnJgP3_tRjeQEPgUn28XctVe3QqmheLZw7QVZDPCyGycDWBaqy7FLpSekET_BftDkewRhyHk9FW_KeEz0ch2c3i08NGNDbr6XYGVayNuSesYk5Aw_p3ICRlUV1bqEwk-Jkzs9EEkQg4hbefqJS6yS1HoV_2EsEhpd_wCQpxK89WPs3hLYZETRJtG5kvCCEOvSHXmDE6eTHGTnEgsIk--UlPe275Dvou4gEAwLofhLDQbMSjnlV5VLsjimNBVcSRFShoxmQwBJR_b2011Y5IuD6St5zPnzruBbZYkGNurQK63TJPWmRd3mbJsGM0mf3CUQ",
"token_type": "Bearer",
"expires_in": "3600",
"expires_on": "1388444763",
"resource": "https://service.contoso.com/",
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4rTfgV29ghDOHRc2B-C_hHeJaJICqjZ3mY2b_YNqmf9SoAylD1PycGCB90xzZeEDg6oBzOIPfYsbDWNf621pKo2Q3GGTHYlmNfwoc-OlrxK69hkha2CF12azM_NYhgO668yfcUl4VBbiSHZyd1NVZG5QTIOcbObu3qnLutbpadZGAxqjIbMkQ2bQS09fTrjMBtDE3D6kSMIodpCecoANon9b0LATkpitimVCrl-NyfN3oyG4ZCWu18M9-vEou4Sq-1oMDzExgAf61noxzkNiaTecM-Ve5cq6wHqYQjfV9DOz4lbceuYCAA",
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctODkwYS0yNzRhNzJhNzMwOWUiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC83ZmU4MTQ0Ny1kYTU3LTQzODUtYmVjYi02ZGU1N2YyMTQ3N2UvIiwiaWF0IjoxMzg4NDQwODYzLCJuYmYiOjEzODg0NDA4NjMsImV4cCI6MTM4ODQ0NDc2MywidmVyIjoiMS4wIiwidGlkIjoiN2ZlODE0NDctZGE1Ny00Mzg1LWJlY2ItNmRlNTdmMjE0NzdlIiwib2lkIjoiNjgzODlhZTItNjJmYS00YjE4LTkxZmUtNTNkZDEwOWQ3NGY1IiwidXBuIjoiZnJhbmttQGNvbnRvc28uY29tIiwidW5pcXVlX25hbWUiOiJmcmFua21AY29udG9zby5jb20iLCJzdWIiOiJKV3ZZZENXUGhobHBTMVpzZjd5WVV4U2hVd3RVbTV5elBtd18talgzZkhZIiwiZmFtaWx5X25hbWUiOiJNaWxsZXIiLCJnaXZlbl9uYW1lIjoiRnJhbmsifQ."
}
2) You add a parse json action after the HTTP call to the log on url. use the sample response from your logon api response.
3) The parse JSON now gives you access to individual fields in the response
Refer a sample work flow which calls the Microsoft AAD endpoint
- The first black box shows you the place where you feed the response from the call to the LogOn API
- The second black box is where you click and provide a sample response from the API so that the engine can generate the schema to parse the response against
- Third box shows you how you can just pass the value of access_token received (as per the sample response added above)
You need to set the token as the value of a variable and use it through your workflow.
Useful links:
https://toonvanhoutte.wordpress.com/2017/09/01/enrich-http-headers-in-logic-apps/
Azure Logic Apps: Extract HTTP Header Key value into a variable
https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-create-variables-store-values
I wanted to generate Azure token from Postman for API authorization in my project. I am able to generate token using below API request but getting the below error message "Authorization denied for this request" while using the generated token in another API request.
Endpoint#
https://login.microsoftonline.com/:tenant_id/oauth2/token
Params#
tenant_id:As per id generation by azure.
Body# (Form-data)
grant_type:client_credentials
client_id:As per id generation by azure.
client_secret:As per id generation by azure.
resource:Required URL
Response#
"token_type": "Bearer",
"expires_in": "foo",
"ext_expires_in": "foo",
"expires_on": "foo",
"not_before": "foo",
"resource": "foo",
"access_token":foo
Since the above returned token is not accepted, I had passed username and password as well in body of the request but ended up with same results. Also azure did not consider my credentials even they are wrong.
Could you please assist what else I need to send in the response to get valid token id?
The Valid format for client_credentials authentication flow is like below:
Azure Portal Credentials For App Id and Tenant Id:
Application Secret from Portal:
Token Endpoint Or URL:
https://login.microsoftonline.com/YourTenantName.onmicrosoft.com/oauth2/token
Request Param:
grant_type:client_credentials
client_id:b603c7be_Your_App_ID_e6921e61f925
client_secret:Vxf1Sl_Your_App_Secret_2XDSeZ8wL/Yp8ns4sc=
resource:https://graph.microsoft.com
PostMan Sample:
Token On Response:
Expose Your Own API:
When You want to authorize your own API you have add it here. So that your token will contain this permission and this API can be accessed. Refer this docs
For more clarity you could refer official docs
You should try adding "X-ZUMO-AUTH" header to your request when using the generated token.
GET https://<appname>.azurewebsites.net/api/products/1
X-ZUMO-AUTH: <authenticationToken_value>
https://learn.microsoft.com/en-us/azure/app-service/app-service-authentication-how-to