【问题标题】:Nuxt Auth extend / modify Google SocialNuxt Auth 扩展/修改 Google Social
【发布时间】:2021-09-24 15:44:06
【问题描述】:

我已经使用 dj-rest-auth / django allauth 设置了社交身份验证。端点期望此信息为 JSON:

不幸的是,在我看来,Nuxt Auth 假设后端应该从 URL 中提取信息,尽管它是作为 POST 请求发送的。 所以会发生什么: 我点击继续使用 Google > Nuxt auth 将我推送到 google > Google 将我推送到我的回调 URL,其中包含 URL 中存在的所有信息。Nuxt Auth 获取该 URL 并按原样发送。

所以我有两个选择:

  1. 我是否尝试修改后端,感觉相当麻烦。
  2. 我是否会以某种方式覆盖 Nuxt 身份验证?我对此一无所知。

文档谈论创建自定义方案: https://auth.nuxtjs.org/guide/scheme

但从那时起,我真的无法弄清楚如何自定义实际发出的后期请求。帮助将不胜感激。

我的 NUXT.CONFIG.JS:

auth: {
    redirect: {
      login: '/register',
      logout: false,
      // callback: '/login',
      home: '/bevakning'
    },
    strategies: {
      google: {
        scope: ['profile', 'email'],
        codeChallengeMethod: '',
        responseType: 'code',
        endpoints: {
          token: 'http://localhost:8000/social-login/google/',
          userInfo: 'http://localhost:8000/auth/user/'
        },
        // withCredentials: true,
      },
      local: {
        token: {
          property: 'key',
          type: 'Token ',
          maxAge: 86400 * 120
        },
        user: {
          // using property: false means it will use the entire json response as user and not just one variable.
          property: false
          // property: 'email'
        },
        endpoints: {
          login: {
            url: '/dj-rest-auth/login/ ',
            method: 'post',
            // propertyName: 'auth_token'
          },
          logout: {
            url: '/dj-rest-auth/logout/',
            method: 'post'
          },
          user: {
            url: '/dj-rest-auth/user/',
            method: 'get',
          }
        },
        // tokenRequired: true,
        // tokenType: 'Token ',
        // globalToken: true,
        autoFetchUser: true,
      }
    }
  },

编辑:解决了我遇到的问题,这是由 Axios 覆盖 nuxt auth 方法引起的。当 content-type 设置为 JSON 时,我意识到有些东西不对劲,但 body 发送时就好像它是 x-www-urlencoded。

【问题讨论】:

    标签: nuxt.js django-allauth nuxt-auth dj-rest-auth


    【解决方案1】:

    原来问题与我使用 Axios 全局添加 application/json 标头有关。 轴:{ // 额外的配置,例如 baseURL: 'http://localhost:8000/', 超时:30, 标题:{ 常见的: { “内容类型”:“应用程序/json”, 接受:“应用程序/json”, }, } },

    这导致 Nuxt Auth POST 请求的 x-www-urlencoded 格式被错误解释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      相关资源
      最近更新 更多