【问题标题】:Grant_type missing in request请求中缺少 Grant_type
【发布时间】:2019-05-02 10:49:13
【问题描述】:

我正在尝试获取对动态 365 的令牌访问(协议 oauth2)。

这是构建和执行 http post 请求的代码:

URI uri = new URIBuilder()
                    .setScheme("https")
                    .setHost("login.microsoftonline.com")
                    .setPath("/"+PropertyUtils.getInstance().getProperty("AD_TENANT_ID")+"/oauth2/token")
                    .setParameter("grant_type", "client_credentials")
                    .setParameter("client_id", PropertyUtils.getInstance().getProperty("CLIENT_ID"))
                    .setParameter("resource", PropertyUtils.getInstance().getProperty("RESOURCE"))
                    .setParameter("client_secret", PropertyUtils.getInstance().getProperty("CLIENT_SECRET"))
                    .build();
            HttpPost post = new HttpPost(uri);
            HttpResponse response = client.execute(post);

响应 json 是:

{"error":"invalid_request","error_description":"AADSTS900144: The request body must contain the following parameter: 'grant_type'.\r ...

为什么响应告诉我grant_type 在请求中作为参数丢失?

【问题讨论】:

    标签: java oauth-2.0


    【解决方案1】:

    您正在尝试执行将这些参数作为查询参数放入 URI 中的请求。虽然这些参数需要以表单 url 编码的形式放入请求的正文中。

    {"Content-Type": "application/x-www-form-urlencoded"}
    

    【讨论】:

    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 2014-10-14
    • 1970-01-01
    相关资源
    最近更新 更多