【问题标题】:Getting Refresh token error in auth0-nextjs application在 auth0-nextjs 应用程序中获取刷新令牌错误
【发布时间】:2022-08-22 23:08:46
【问题描述】:

我们正在使用 NextJS 构建一个 Web 应用程序(单页应用程序)。其中我们使用 auth0 进行登录。我们遇到了奇怪的问题,登录后我们收到一条错误消息 Error: A refresh token is required to refresh the access token, but none is present.

我们有getAccessToken.js 文件,我们在其中添加了所有必要的配置来获取令牌,但仍然出现错误。

const afterRefresh = (req, res, session) => {
    console.log(\"sess\", session);
    delete session.idToken;
    return session;
};
export default async function MyHandler(req, res) {
    const token = await getAccessToken(req, res, {
        refresh: true,
        afterRefresh,
    });

我们还在[...auth0].ts 文件中将scope 设置为offline

export default handleAuth({
    async login(req, res) {
        try {
            await handleLogin(req, res, {
                authorizationParams: {
                    audience: \"gateway.dev.abcdDomain.com\",
                    // Add the `offline_access` scope to also get a Refresh Token
                    scope: \"openid profile email offline_access\", // or AUTH0_SCOPE
                    useRefreshTokens: true,
                },
            });
        } catch (error) {
            res.status(error.status || 400).end(error.message);
        }
    },

nextjs-auth0 库中的get-access-token.tsaccessTokenRequest 是布尔值

export interface AccessTokenRequest {
  /**
   * A list of desired scopes for your Access Token.
   */
  scopes?: string[];
  /**
   * If set to `true`, a new Access Token will be requested with the Refresh Token grant, regardless of whether
   * the Access Token has expired or not.
   */
  refresh?: boolean;

知道我们哪里出错了。

    标签: node.js reactjs authentication next.js auth0


    【解决方案1】:

    从范围和行中删除 offline_access - useRefreshTokens: true,

    当您在 auth0 仪表板中启用刷新令牌时,应插入它。否则不要包含它。

    参考: https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 2017-12-28
      • 2021-06-12
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 2017-05-02
      • 2019-12-15
      • 2017-12-12
      相关资源
      最近更新 更多