google-oauth-java 如何处理重定向?

发布于 2024-10-01 07:58:10 字数 1037 浏览 1 评论 0原文

我正在使用 google-oauth-java ,真正让我的生活变得复杂的一件事是当我尝试使用 OAuthClient.invoke() 时,由于请求返回代码 302 而不是 200,我经常会抛出 OAuthProblemException 。因此,我发现自己重写了 invoke 代码并使用OAuthClient.access() 代替。我想知道我是否缺少某种类型的 followRedirect 设置?该文档不存在,示例也没有真正的帮助,有人可以在这里帮助我吗?

这是 OAuthClient 的片段来说明

public OAuthMessage invoke(OAuthMessage request, ParameterStyle style)
        throws IOException, OAuthException {
    OAuthResponseMessage response = access(request, style);
    if ((response.getHttpResponse().getStatusCode() / 100) != 2) {
        OAuthProblemException problem = response.toOAuthProblemException();
        try {
            problem.setParameter(OAuthProblemException.SIGNATURE_BASE_STRING,
                                 OAuthSignatureMethod.getBaseString(request));
        } catch (Exception ignored) {
        }
        throw problem;
    }
    return response;
}

I'm using google-oauth-java and one thing that really complicates my life is that when I attempt using OAuthClient.invoke() I frequently get OAuthProblemException thrown due to request returning code 302 instead of 200. Because of that I found myself rewriting invoke code and usingOAuthClient.access() instead. I'm wondering if I'm missing some type of followRedirect setting? The documentation is non-existing and examples don't really help, can someone help me here?

Here's snippet from OAuthClient to illustrate

public OAuthMessage invoke(OAuthMessage request, ParameterStyle style)
        throws IOException, OAuthException {
    OAuthResponseMessage response = access(request, style);
    if ((response.getHttpResponse().getStatusCode() / 100) != 2) {
        OAuthProblemException problem = response.toOAuthProblemException();
        try {
            problem.setParameter(OAuthProblemException.SIGNATURE_BASE_STRING,
                                 OAuthSignatureMethod.getBaseString(request));
        } catch (Exception ignored) {
        }
        throw problem;
    }
    return response;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花辞树 2024-10-08 07:58:10

由于我使用 OAuthClient.access() 处理了这个问题并且没有人挺身而出,我将接受我自己的解决方案

Since I dealt with this by using OAuthClient.access() and nobody is coming forward I'm going to accept my own solution

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文