【发布时间】: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 并按原样发送。
所以我有两个选择:
- 我是否尝试修改后端,感觉相当麻烦。
- 我是否会以某种方式覆盖 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