首页 > 解决方案 > 使用 nodejs 获取重定向数据

问题描述

所以我正在使用node-myanimelist npm 包,它是myanimelist API的包装器,并且该包使用pcke-challenge提供挑战(基本上用户转到一个 url,授权并使用访问令牌重定向用户以供我使用)。这是下面的图片来清除这个想法 在此处输入图像描述

单击允许后,用户将被重定向到您使用访问令牌指定的 URL。但是这里有一个问题,我的应用程序没有网站,也没有将用户重定向到的地方,那么当用户点击允许时仍然获得令牌的最佳方法是什么?

编辑:

这是代码:

const { Mal, Jikan } = require('node-myanimelist');
const auth = Mal.auth(/* app_id */);
const pkceChallenge = require("pkce-challenge");
const pkce = pkceChallenge();

// This is the URL the user gets
const url = auth.getOAuthUrl(pkce.code_challenge);

// "code" here is what clicking allow on the URL above ^ returns with the redirect
const acount = await auth.authorizeWithCode(code,pkce.code_challenge);

// From then on I can do stuff like `account.anime.search(/* stuff */)`

标签: node.jsapiauthentication

解决方案


推荐阅读