Discord Oauth2 Webhook令牌交换

时间:2018-10-04 08:20:29

标签: java spring spring-boot oauth discord

我正在尝试将Discord webhooks与我的应用程序集成。

我在用户验证后从Discord获得了授权代码,现在我必须将其交换为令牌。

我通过以下方式发送了POST:   client_id,client_secret,grant_type,代码,redirect_uri和范围 following the docs。我没有获得令牌,而没有获得 403禁止。

问题是,当我通过Postman进行操作时正在运行!!它在我的Spring Boot应用程序中无法正常工作,因此我可能在这里缺少了一些东西。

我尝试了两种方法,首先:

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

HttpEntity entity = new HttpEntity(headers);
    String path = String.format(discordOauthAccessUrl, discordClientId, discordClientSecret, discordGrantType, discordAuthData.getCode(), discordRedirectUri, discordScope);
    System.out.println(path);
    ResponseEntity<Object> object = restTemplate.exchange(
            path,
            HttpMethod.POST,
            entity,
            Object.class);

路径如下:

https://discordapp.com/api/oauth2/token?client_id=%s&client_secret=%s&grant_type=%s&code=%s&redirect_uri=%s&scope=%s

秒:

        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
    map.add("client_id", discordClientId);
    map.add("client_secret", discordClientSecret);
    map.add("grant_type", discordGrantType);
    map.add("code", discordAuthData.getCode());
    map.add("redirect_uri", discordRedirectUri);
    map.add("scope", discordScope);
    HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);

    ResponseEntity<Object> response = restTemplate.postForEntity(discordOauthAccessUrl, request, Object.class);

请求的请求看起来像这样:

<{client_id=[X], client_secret=[X], grant_type=[authorization_code], code=[X], redirect_uri=[http://X], scope=[webhook]},{Content-Type=[application/x-www-form-urlencoded]}>

我可能缺少一些愚蠢的东西,因为它通过Postman工作。 任何帮助将不胜感激。

0 个答案:

没有答案
相关问题