【发布时间】:2020-06-26 16:46:06
【问题描述】:
我需要从 URL 获取授权码。它作为查询字符串参数存在。
当我运行以下网址时
https://XXX.authenticaion.com/oauth/authorize?response_type=code&client_id=sb!t113
它重定向到 http://localhost:8080/?code=8wFgU1GJo3
我需要解析 localhost URL 并获取代码。
请帮助如何检索代码
代码:
const url = 'https://XXX.authenticaion.com/oauth/authorize?response_type=code&client_id=sb!t113'
const config = {
method: "GET"
};
const response = await fetch(url ,config);
console.log('Response Text...............'+response.text())
【问题讨论】:
-
需要解析localhost url来提取code参数吗?
-
是的,没错
-
但问题是,它是一个重定向 URL,我只有在第一个 URL 运行后才知道 locla 主机 URL
-
那么你尝试从当前页面查询字符串中获取它,而不是解析 URL
-
没错..当我运行第一个 URL 时,它会从那里重定向到本地主机 URL,我会拿起代码..
标签: javascript node.js