如何在 nextjs 中的 OAuth 流程后从 URL 捕获令牌

问题描述 投票:0回答:0

我正在构建一个 Next.js 应用程序,我的最终用户可以授权我代表他们从不同的第 3 方解决方案中获取他们的付款/订单数据。第 3 方解决方案可能是

  1. 条纹
  2. 贝宝
  3. 亚丁
  4. 一些会计系统 通过使用他们的 API。

它会像这样工作:

  1. 用户点击我网站上的 SomeAccountingSystem 徽标,然后将他们带到 SomeAccountingSystem 的授权页面。
  2. 他们登录成功了。
  3. 他们被重定向回我的网站,但现在的 URL 是:

http://<mycoolsite.org>/connections?code=<TOKEN_RETURNED>&state=somestate123

现在重定向到 SomeAccountingSystem 授权页面看起来像这样

<a href="https://apps.SomeAccountingSystem.com/oauth-v1/auth?client_id=<MY_CLIENT_ID>&redirect_uri=http://localhost:3000/connections/&state=somestate123&access_type=offline&response_type=code&account_type=service">
   SomeAccountingSystem 
</a>

我的问题是:

  1. 如果我使用 Auth0 或 next-auth,我如何在用户被重定向回我的站点后捕获 ?我应该为此使用中间件吗?
  2. next-auth 或 Auth0 等第三方解决方案可以解决这个问题吗?
html reactjs next.js auth0 next-auth
© www.soinside.com 2019 - 2024. All rights reserved.