【发布时间】:2021-03-18 11:09:37
【问题描述】:
我在 Electron 中有一个 React 应用程序,我正在尝试使用 spotify-web-api-node 库访问 spotify API。但是,我不确定 oauth 流究竟是如何在 Electron 应用程序中工作的……首先,对于重定向 URL,我使用了 this question 并在我的文件中添加了一个 registerFileProtocol 调用。然后我添加了一个特定的ipcMain.on 处理程序来接收来自页面的spotify 登录调用,我已经确认它适用于控制台日志。但是,当我真正调用authorizeURL 时,什么都没有发生?
这是我的 main.js 的一部分:
app.whenReady().then(() => {
...
protocol.registerFileProtocol(
"oauthdesktop",
(request, callback) => {
console.log("oauthdesktop stuff: ", request, callback);
//parse authorization code from request
},
(error) => {
if (error) console.error("Failed to register protocol");
}
);
});
ipcMain.on("spotify-login", (e, arg) => {
const credentials = {
clientId: arg.spotifyClientId,
clientSecret: arg.spotifySecret,
redirectUri: "oauthdesktop://test",
};
const spotifyApi = new SpotifyWebApi(credentials);
console.log("spapi: ", spotifyApi);
const authorizeURL = spotifyApi.createAuthorizeURL(
["user-read-recently-played", "playlist-modify-private"],
"waffles"
);
console.log("spurl: ", authorizeURL);
axios.get(authorizeURL);
}
我希望出现典型的 spotify 登录页面弹出窗口,但这不会发生。我也希望(可能)registerFileProtocol 回调记录一些东西,但事实并非如此。我要在这里做什么? authorization guide 特别提到在 auth url 上执行 GET 请求,这就是我在这里所做的......
【问题讨论】:
标签: node.js oauth-2.0 oauth electron