【问题标题】:Pass a string through Discord OAuth?通过 Discord OAuth 传递字符串?
【发布时间】:2020-03-10 11:42:24
【问题描述】:

我想知道是否可以使用 Discord OAuth(识别范围)同时将重要的补充信息传递给重定向 URL。

site with [important variable] > oauth page > site that needs [important variable] and oauth result

我尝试添加类似 ?variable="myString" 的内容,但它会剪掉除 OAuth 信息之外的所有不必要的 URL 参数。 Discord OAuth 也不太喜欢使用 iframe,所以这不是这里的解决方案。

【问题讨论】:

  • 所以基本上你想在授权过程开始时传递一个字符串,并且你想在返回的 URI 上接收相同的字符串而不做任何更改?我理解正确吗?

标签: javascript oauth oauth-2.0 discord discord.js


【解决方案1】:

我已经写了一篇关于这个问题的帖子,你可以在这里找到它:

https://levbuchel.com/passing-variables-through-oauth


原答案:

要通过 oAuth 流程传递变量,您应该使用 state oAuth 参数。

首先用你的参数创建一个 Json 字符串,

例如{'first':'111', 'second':'222'}

然后将其编码为base64,这样作为URL传递时就不会被修改。

将此字符串作为state (api/oauth2/authorize?response_type=token&state=whatEverYouGotAsState) 传递。

然后您将能够在重定向 URI 上接收并解码它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 2017-07-25
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多