如何将Slack的OAuth2与Java桌面应用程序一起使用 [英] How to use Slack's OAuth2 with a Java desktop application

查看:185
本文介绍了如何将Slack的OAuth2与Java桌面应用程序一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用OAuth2使用Slack对java桌面应用程序进行身份验证?我正在尝试关注 Slack的指南

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

我遇到了问题,因为它说你在应用程序的重定向uri中获得了访问令牌。但由于我正在制作的应用程序在Web浏览器中不存在,无论如何我能做到吗?

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?

我的java应用程序可以启动它可以与之通信的localhost站点以用作重定向uri吗?如果是这样,怎么样?

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

推荐答案

桌面应用程序作为内部集成

在我们了解更多详细信息之前,请注意,如果您计划仅将自己的桌面应用程序用于自己的Slack工作区,则可以使用简单的解决方案。在这种情况下,您的应用程序不需要支持完整的Oauth工作流程,您有两种选择:

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)

我还想提前澄清你的应用只需要运行Oauth进程ONCE进行安装它进入了一个新的Slack工作区。生成的令牌没有到期日期且无法刷新。

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.

多个Slack工作区的桌面应用

如果您计划将桌面应用程序分发到多个Slack工作区,则需要支持完整的Oauth安装过程。

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

Slack正在使用Oauth 2.0 ,原则上这个旧的 Oauth的所有标准答案wiki文章也适用于Slack。

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

但是,因为你不能假设你的用户的本地机器可以通过互联网访问(例如重定向回来)到本地Web服务器将无法工作,因为Slack很可能无法访问它,您将需要一个在Web服务器上运行并可从Internet访问的Web帮助应用程序。

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.

这个网络助手应用程序基本上是一个小型网站,可以执行完整的Oauth舞蹈安装过程进入新的Slack工作区。您的应用程序可以打开浏览器窗口并重定向到Web帮助应用程序以启动登录过程。然后,您有两种基本方法来处理连接回桌面应用程序:

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:


  • 向用户显示生成的令牌并要求他副本&将
    粘贴到您的桌面应用程序(简单方法)

  • 将生成的令牌存储在您的Web帮助应用程序中,并为您的桌面应用程序提供API以自动获取它。 (用户友好的方法)

如果您正在寻找这样的网络助手应用程序的起点,请看一下<用于安装Slack应用程序的href =https://github.com/ErikKalkoken/slackapp =nofollow noreferrer>示例PHP脚本。

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.

这篇关于如何将Slack的OAuth2与Java桌面应用程序一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆