java - 如何从重定向响应中获取授权码
问题描述
我正在为 Spotify 使用 Java 包装器,并且我正在尝试找到一种从重定向 URI 获取授权代码的方法,以便在请求访问令牌时可以使用它。我是 OAuth 的新手,所以任何帮助都会很棒!谢谢!
我能够从浏览器重定向复制代码并将其硬编码到我的代码中。
解决方案
您需要将 redirect_uri 参数设置为 Servlet url。
@WebServlet("your/servlet/Url")
public class MyServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public MyServlet()
{
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//get the authorization code
String code = request.getParameter("code");
//get tokens and use them as per your requirement using code
...
//redirect user to the final destination
response.sendRedirect("url");
}
}
推荐阅读
- javascript - 根据javascript中的条件使用正则表达式突出显示字符串中的数字
- google-sheets - 使用 drive.file 范围将行附加到 Google 表格
- c# - 我的相机旋转不正确是否有原因?
- azure - 普通数据服务和源之间如何同步数据?
- python - 烧瓶 MySQL LIKE concat 查询中的语法错误
- java - 查找 YouTube 视频中提到的单词的单词搜索
- java - camel-rabbitmq:如何在一个 URI 中表达多个绑定参数?
- javascript - 如何从脚本本身内部的自加载脚本中获取参数
- c# - 编译器抱怨未分配的结构变量,但允许分配成员 - 为什么?
- java - 添加了一个本地外部 JAR 文件。现在应用程序在本地运行,但从 docker 给出 ClassNotFoundException