Receiving webhook from GitHub from C# Console App - c#

I'd like to capture webhooks from GitHub (for various events, like commits, etc), from my C# console application. I figured I could "listen" to an endpoint and webhooks would be thrown there, but it seems that perhaps github is actually sending webhooks to endpoints that you need to setup and listen from.
If the latter is this case, then I suppose I'll need to setup a web server to capture the webhooks. If the former is the case, then I'm not finding in the docs how I can listen for webhooks from GitHub?

Your question isn't very clear, but I think you're on the right track vis-a-vis implementing a web server. So, my answer to your question is: you need to implement a web server to receive the webhook requests.
Edit
At the bottom of this document, you will find instructions on how to implement a very simple web server (in Ruby) to receive GitLab webhook requests. I know this isn't a turnkey solution for you, but hopefully it will help get you going.

Related

Add new protocol "listener" to asp.net generic host

I'm not even sure how to express this question which is likely why my normal google-Fu failed me. So here goes. Visual studio has several project templates that the generic host. There is the worker service for console applications, webhost for asp.net and an template for grpc.
All those hosts somehow translate a request over a certain protocol to actions in the application. Webhost uses Http as a communications layer, grpc uses grpc. NServicesBus uses messagequeue's.
I'm trying to find examples of what is needed to implement a custom "protocol mapper" Does anyone know of any example to do this? Or basic documentation on what would need to be implemented.
Basically what is behind functions like ConfigureWebhostDefaults or UseNServiceBus for NServiceBus etc etc.. Soemthing that listens for network calls or other events and then fires up the correct function in the correct controllers to use MVC terms.
This is not the clearest question I have asked, but it does not help if one does not know how the thing you are looking for is named.

How to handle slash command post requests from slack in C#

I am currently trying to setup a slack bot in C# using azure. I am new to interacting with http requests in C#, and am having trouble getting the post request from slack to work. When I call my slash commands in slack, I am met with an http_client_error and no other error information. Does anyone have any resources they could point me towards about working with slack commands in c#. Any recent help would be much appreciated. I cannot program the bot in another language due to limitations of a dll I am using. I guess the main question I have is how to handle http post requests from slack in C#.
When you give slack the link that it needs to send the HTTP Post to, make sure you have https:// at the start of the link.

How to set up authorization with OAuth in SlackAPP for new users?

I have a c#-based program that can send messages and files to our SlackWorkspace via my SlackApp (I'm using HttpClient to communicate with Slack).
Now, to distribute this program in my workspace and to make it so that every user will have his own identity, it says that I have to use OAuth and create verification-tokens, specific for each user.
It says in the Slack-documentation I have to use a redirect-URL (as per docs) to my own server.
We have a server that I potentially could use for this. But I have never done anything like this before and I am unclear on what "answer" I have to provide from our server. I thought the verification-process would be handled by Slack.
Anyone has an idea on how to approach this?
And before anyone asks - yes we need to install it for everyone and make them identifiable as themselves. We can't use the "SlackApp" as user. :)
I would be very grateful for code examples(in c#) and explanations on how this whole redirect-thing is working.
Slack uses the standard Oauth 2.0 protocol to authenticate apps, similar to Google and Facebook.
So the "verification-process" is indeed mostly handled by Slack (as outlined here), but your Slack app needs to initiate it and handle the responses properly. Also its a multi-step process and includes the user having to login into Slack with their credentials. This why you need a web app to handle the whole process.
To enable a Slack app to generate tokens via Oauth a web app is needed:
can be reached from the Internet
able to handle HTTP requests like a web server
has persistent storage for the newly generated tokens
This is probably easier to implement with ASP.NET Web Pages, which can utilize many functions from an existing web server.
But for this answer, lets look on an implementation in .NET Core. For that we need to create our own web server and some rudimentary session handling. Main concepts include:
HttpListener class for providing fundamental ability to listen and respond to HTTP requests
Handle multiple requests in parallel
Cookies / Session handling
MD5 hashes
The details go a bit beyond the scope of one answer. But I am happy to share a working example implementation on this GitHubGist.
Btw: For the local development of such a web app its recommend to use a VPN tunnel like ngrok, that allows one to expose a local machine securely to the Internet and Slack.

Consuming a webhook in asp.net mvc application

I am learning how to consume a webhook in ASP.Net MVC solution, the webhook can be from OneDrive, GitHub or Twilio (or anyone), but I am not able to find even a basic example of consuming webhooks. I tried different keyword and searched the web but I haven't found a basic tutorial for this.
I am willing to put the controller code of my MVC Project but I don't know how to consume webhooks.
I did my research and I could not find any basic example for consuming webhooks. I am starting to wonder is there any synonym terms for webhooks I should be entering into a search engine?
Links I looked into: VS Hooks
To listen a webhook you basically need a controller with some method that allows HttpPost request. The system who fires the webhook must have some doc/config to know method name and params. Usually you need a DNS or public ip to get the request
#Mate already answered this using example from https://ngrok.com/

IdentityServer3 alternative to webbrowser navigating event

I am working on a POC for IdentityServer3.
I have a version of sample app WebHost (minimal) running alright.
For the client sample app I am using the wpf client (hybrid with pkce).
I need the hybrid example because the webhost has been modified to use a custom ExternalRegistrationUserService.
However, all the samples they have for the hybrid clients use the webserver navigating event which uses a threading model not recommended for console apps/windows services.
The punchline question is, is there a console friendly equivalent to navigating that's not tied to a ui control?
httpwebrequest almost does what I want but identityserver3 seems to want to send multiple responses in a chain that I need to intercept and any httpclient or httpwebrequest call I make seems to want to return the first response only.
I just wrote a very similar POC using information from a recent blog post by Dominick Baier.
Essentially, this approach has the native client app using a combination of the newish IdentityModel.OidcClient library and a local HTTP listener to receive redirects.
I contributed to one of Dominick's samples that shows how the OidcClient can be used with the HTTP listener to enable the hybrid flow in a console application. You can find the code here.
I think this sample will do what you are after, but it does externally pop open the system web browser. However, the OidcClient also supports a user supplied WebView if you wanted to do everything inside the native client.

Categories

Resources