aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

Unable to receive webhook from github #53

Closed andredublin closed 8 years ago

andredublin commented 8 years ago

I've been unable to receive a webhook POST request from github. I've followed a couple guides to figure out the process of enabling the github webhook http://tools2151.rssing.com/chan-4147006/all_p15.html https://blogs.msdn.microsoft.com/webdev/2015/09/04/introducing-microsoft-asp-net-webhooks-preview/

But I'm consistently meet with this error

{"message":"Could not find a valid configuration for WebHook receiver 'github' and instance ''. The setting must be set to a value between 16 and 128 characters long."}

Using the connected services, my web.config is populated with the proper appSetting MS_WebHookReceiverSecret_GitHub, and my project receives two new files WebHookConfig.cs and GitHubWebHookHandler.cs

Is there some other configuration step I'm missing?

HenrikFrystykNielsen commented 8 years ago

Did you set the app setting in the web.config directly or via the Azure portal? In the former case, does the app setting look something like this:

  <appSettings>
    <add key="MS_WebHookReceiverSecret_GitHub" value="12-128 secret"/>
  </appSettings>
andredublin commented 8 years ago

The appSettings was updated by the Add Connected Service process.

Here is the resulting web.confg

  <appSettings>
    <add key="MS_WebHookReceiverSecret_GitHub" value="e4f76bd075498f67bb2703dffd481110a7f7b49983d5ab736b4597612eb59616"/>
  </appSettings>

Please note that is not the actual sha256 token I used, but it is that length

HenrikFrystykNielsen commented 8 years ago

Are you sure your web.config is deployed along with the service? The message indicates that it can't find it.

andredublin commented 8 years ago

Yeah, I'm positive the web.config is deployed with the service as I'm reading other values within the appSettings xml tags

HenrikFrystykNielsen commented 8 years ago

I am not sure what is going on. I just added a sample for GitHub https://github.com/aspnet/WebHooks/tree/dev/samples/GitHubReceiver and used it with your sample key above and it works fine. When I look at the output from the service deployed in Azure I get this:

w3wp.exe Information: 0 : Registered 'IWebHookReceiver' instances with the following names: github.
w3wp.exe Information: 0 : Processing incoming WebHook request with receiver 'github' and id ''.
w3wp.exe Information: 0 : Registered configuration setting 'GitHub' for ID '''.

Can you please check if you see this?

andredublin commented 8 years ago

I think my situation is that I have a web api and mvc app along with a custom iniject resolver and there may be some issue before the dubgger can attach to the process. It may be best for me to start with a clean web api project and work from there. Thanks for the help!

andredublin commented 8 years ago

So I found that my problem was a result of using the custom ninject resolver. Once I commented out the lines that initialized the ninject DI container I was able to receive post requests from github.

HenrikFrystykNielsen commented 8 years ago

Interesting -- ASP.NET WebHooks has been designed to work with any DI used together with Web API and MVC so it should be able to get to work. Which parts were managed by DI in your project? The usual stuff like Controllers etc.? What else? I have tried it with Autofac but not Ninject,

andredublin commented 8 years ago

Correct just controllers, and they are using construction injection for data access and other services.

HenrikFrystykNielsen commented 8 years ago

I see what is going on -- Ninject thinks it knows how to create SettingDictionary even though it isn't registered with the container. Further, as it uses reflection to create it, it doesn't get initialized with current app settings but instead as empty which is why you get the error you see. Interesting.

HenrikFrystykNielsen commented 8 years ago

Committed a fix for ninject to not return empty setting dictionary: 3ae18e675eb4295303558bd28e3bcabc1546b006

mattscully commented 8 years ago

In case anyone else is looking for a workaround, most DI frameworks let you register a Func for a given type. This fixed it for me using StructureMap:

_.For<SettingsDictionary>().Use(() => CommonServices.GetSettings());

This way I can continue letting my DI container resolve my WebHookHandlers.

HenrikFrystykNielsen commented 8 years ago

Good point!