Here is update after coming up with a solution
Trying to to save whoever reads this some. The problem had to do with a web site I created which uses ASP.Net forms authentication. You login with a userid/password and that generate a security token/cookie that is then is passed in with each request from the client. Once the user is logged in they are then presented a screen with buttons to click for opening and close the garage door. This web site also hosts a web service. These service methods get called, via webhooks, by the Photon. But when the Photon calls the service method it is doing so as an unauthenticated user and gets a 401 Unauthorized response.
One solution would be to come up with an approach to generate an authentication cookie, pass it to the Photon, and then find a way to have that cookie passed in the particle.Publish.
But this is way too much work. So I came up with a compromise where some of the service methods are non-secured and public exposed the rest are are secured (require an authentication cookie). The non-secured ones are used by the webhooks and they fortunately don’t do anything that is needing to be protected (like opening and closing the door!)
Original Post
Not sure if this is going to make sense but I’ll try.
I’ve created a webservice that I’m wanting to use as the endpoint to collect sensor data from a photon. I could use one of many publicly available services that exist for this purpose but for learning purposes I’m wanting to do it myself. The service lives in a web site that also presents some web pages that provide a front end for a garage door opener application. The web application is ASP.Net a with Forms authentication.
I’m wanting the photon periodically publish sensor data to the service. I’ve tested everything locally and am now wanting to get the same thing working when the app is running on my hosting provider. But the webhook fails with a 401 unauthorized error if it’s running there. I’m using https when the site is hosted.
I’m able to run this service locally (after opening up my web server to the internet) with webhook is pointing to my publicly opened web server WAN address.
Test run where Publish hits my local server.
event: TestPublishReportGargeStatus
data: {"data":"{\"op\":\"Monitoring\", \"all\":[{\"t\":\"2017-01-15 20:29:37\",\"o\":\"1\",\"c\":\"0\",\"v\":\"160\",\"h\":\"123\",\"s\":\"53\"}]}","ttl":"60","published_at":"2017-
01-15T20:29:37.405Z","coreid":"999999999999999999999999"}
event: hook-sent/TestPublishReportGargeStatus
data: {"data":"undefined","ttl":"60","published_at":"2017-01-15T20:29:37.449Z","coreid":"particle-internal"}
event: hook-response/TestPublishReportGargeStatus/0
data: {"data":"{\"d\":null}","ttl":"60","published_at":"2017-01-15T20:29:37.499Z","coreid":"particle-internal"}
Webhook pointing to my local IIS
{
"id": "587ba742c34666275672b924",
"event": "TestPublishReportGargeStatus",
"created_at": "2017-01-15T16:45:54.032Z",
"mydevices": true,
"url": "http://[MY WAN ADDRESS]/WebService1.asmx/PublishReportGargeStatus",
"requestType": "POST",
"json": {
"sound": "{{sound}}",
"vibrateHoriz": "{{vibrateHoriz}}",
"vibrateVert": "{{vibrateVert}}",
"doorClosed": "{{doorClosed}}",
"doorOpen": "{{doorOpen}}"
},
"noDefaults": false,
"rejectUnauthorized": true
},
Test run when trying to use the service that is residing at my public hosting site
event: ProdPublishReportGargeStatus
data: {"data":"{\"op\":\"Monitoring\", \"all\":[{\"t\":\"2017-01-15 20:18:55\",\"o\":\"1\",\"c\":\"0\",\"v\":\"152\",\"h\":\"112\",\"s\":\"54\"}]}","ttl":"60","published_at":"2017-
01-15T20:18:56.666Z","coreid":"999999999999999999999999"}
event: hook-sent/ProdPublishReportGargeStatus
data: {"data":"undefined","ttl":"60","published_at":"2017-01-15T20:18:56.700Z","coreid":"particle-internal"}
event: hook-error/ProdPublishReportGargeStatus/0
data: {"data":"error status 401 from www.myinternetsite.com","ttl":"60","published_at":"2017-01-15T20:18:56.918Z","coreid":"particle-internal"}
Webhook for the hitting the public running service
{
"id": "587bd6ba7b017726e6f0b486",
"event": "ProdPublishReportGargeStatus",
"created_at": "2017-01-15T20:08:26.174Z",
"mydevices": true,
"url": "https://www.myinternetsite.com/WebService1.asmx/PublishReportGargeStatus",
"requestType": "POST",
"json": {
"sound": "{{sound}}",
"vibrateHoriz": "{{vibrateHoriz}}",
"vibrateVert": "{{vibrateVert}}",
"doorClosed": "{{doorClosed}}",
"doorOpen": "{{doorOpen}}"
},
"noDefaults": false,
"rejectUnauthorized": true
}
I’m thinking some authorization “thing” needs to be passed via the web hook. I updated the webhook by addding the auth token (see webhook documentation). The auth keyword lets you pass a userid and password. But that didn’t work. I also tried “rejectUnauthorized”: false in the webhook definition and that failed as well.
Any ideas?
Thank you.