Discourse Connect: How implementing Discourse login with an existing database?

You will need to create a small web service that connects to that database, and when receives a redirect with those parameters prompts the user for username and password and then redirects the user back to Discourse.