我已经建立了使用django /django的社会认证。端点期望此信息为JSON:

不幸的是,在我看来,就像Nuxt一样,假设后端应该从URL中提取信息,尽管它将其作为POST请求发送。所以所发生的是:我点击“继续使用Google > Nuxt”将我推到google > Google将我推到回调URL上,其中包含了URL中的所有信息。Nuxt获取这个URL,然后按原样发送出去。

所以我有两个选择:
我是否尝试修改后端,这感觉相当troublesome.
文档讨论如何创建自定义方案:https://auth.nuxtjs.org/guide/scheme
但从那时起,我真的无法理解如何定制实际的生成的post请求。我会感谢你的帮助。
我的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方法之上。当内容类型被设置为JSON时,我意识到有些东西被关闭了,但是身体被发送,就好像它是x-www-urlencoded一样。
发布于 2021-09-24 18:35:14
结果发现,这个问题与我用Axios全局添加一个应用程序/json头有关。axios:{ // baseURL:'http://localhost:8000/',超时值: 30,标题:{公用:{“Content”:"application/json",接受:"application/json",},}
这导致了对Nuxt Auth POST请求的x-www-urlencoded格式的错误解释。
https://stackoverflow.com/questions/69317812
复制相似问题