I have created a webhook custom sender project as described in here. When I try to subscribe to the webhook using postman I get a login error. As per my understanding to subscribe, I must provide a dashboard sort of thing where users come and subscribe to events. I want the user to call the subscription API directly from there own app. how I can do that? I don't see any documentation which tells me about all the parameters in the subscription request. need help.
Asked
Active
Viewed 832 times
1
-
You do not need a dashboard or some sort of UI to create a registration. See [my repo](https://github.com/Expecho/Self-Hosted-Asp.Net-WebHooks/blob/master/Receiver/Program.cs#L28) for an example subscribe method. But do mind you have to be authenticated to the api that will send to the webhook. – Peter Bons Sep 22 '17 at 07:05
-
Thankyou peter. I tried posting to my sender subscription URL as you have done but When I post to /api/webhooks/registrations I get my login page in response. is there something I need to do at my webapi configuration level to allow all the requests without login? – muhammad kashif Sep 22 '17 at 07:09
-
1In order for webhooks to work you need authentication (because the webhook sender needs to know which user to address). So if you are using postman be sure to include any authorization headers required. – Peter Bons Sep 22 '17 at 07:12
-
So, whoever wanna use my web hook sender, first he must create a user ? only then he can subscribe ? – muhammad kashif Sep 22 '17 at 07:15
-
Yes, that is correct. If you take a look at the [source code](https://github.com/aspnet/WebHooks/blob/master/src/Microsoft.AspNet.WebHooks.Custom/WebHooks/WebHookManager.cs#L85) you will see it needs a valid user to send out webhooks. – Peter Bons Sep 22 '17 at 07:19
-
To be clear, you have to authenticate against the sender of the webhook. You do not need authentication on the controller that receives the webhook (the POST action you specify in the registration). – Peter Bons Sep 22 '17 at 07:21
-
I am understanding this. Now I am thinking how I am gonna authenticate the user. actually before that how I am gonna create a user for each my subscriber. – muhammad kashif Sep 22 '17 at 07:29
1 Answers
0
You get the login error because you probably decorated the controller with Authorize
attribute and you need to be logged in in order to access the actions within. You can replace AllowAnonymous
attribute if you don't need to be logged in.
If you do, then login normally on the site and grab that cookie(token, etc.) which holds the authentication information and send that along with the Postman request.

Mihail Stancescu
- 4,088
- 1
- 16
- 21
-
This is what I am trying to understand. The subscription request goes to "/api/webhooks/registrations" which is inside web hook API ( I have no control over them). What I am suspecting is this that I may need to change some web api configuration to allow anonymous requests. – muhammad kashif Sep 22 '17 at 07:12
-
Yes, you should allow anonymous access to the callback that the subscription is using on your API. You can do this only to the controller handling the subscriptions calls by adding/replacing the `AllowAnonymous` attribute. – Mihail Stancescu Sep 22 '17 at 07:16