3
votes

Is there a way to authenticate a java desktop application with Slack using OAuth2? I am trying to follow Slack's guide.

I am getting stuck because it says you get the access token inside of the redirect uri of your application. But since the app I am making does not exist inside of the web browser, is there anyway I can do this?

Can my java application launch a localhost site that it can communicate with to use as the redirect uri? If so, how?

1
Here is the general answer to the topic with Oauth 2.0: stackoverflow.com/questions/13753969/…Erik Kalkoken

1 Answers

1
votes

Desktop app as internal integration

Before we get into more details please note that there is an easy solution if you plan to use your desktop app for your own Slack workspace ONLY. In that case your app does not need to support the full Oauth work flow and you have two options:

  • Install your app as internal integration via the management page of your Slack app and then copy & paste the token to your desktop app
  • Create a legacy token for your Slack workspace and then copy & paste to your desk (not recommended)

I also like to clarify upfront that your app only needs to run the Oauth process ONCE for installing it into a new Slack workspace. The resulting token has no expiration date and has not to be refrehed.

Desktop app for multiple Slack workspaces

If you plan to distribute your desktop app to multiple Slack workspaces you will need to support the full Oauth installation process.

Slack is using Oauth 2.0, so in principle all the standard answers from this older Oauth wiki article should work for Slack too.

However, since you can not assume that the local machines of your users are reachable from the Internet (e.g. redirecting back to a local web server will not work, since Slack will most likely not be able to reach it), you will need a web helper app that runs on a web server and is reachable from the Internet.

This web helper app is basically a small web site, which performs the complete Oauth dance for the installation process into a new Slack workspace. You app can open a browser window and redirect to the web helper app to start the login process. You then have two basic approaches how to handle the connect back to your desktop app:

  • Show the resulting token to the user and ask him to copy & paste it to your desktop app (simple approach)
  • Store the resulting token in your web helper app and provide an API to your desktop app to fetch it automatically. (user-friendly approach)

If you are looking for a starting point for such a web helper app, take a look at this example PHP script for installing Slack apps.