英文:
Get token from Laravel in Nuxt 3 authorization process using sidebase/nuxt-auth and GoogleProvider
问题
我在 nuxt 3.2.3
中使用 @sidebase/nuxt-auth 0.5.0-rc.0
进行授权。我这样定义了 Google 提供程序:
GoogleProvider.default({
clientId: 'secret.apps.googleusercontent.com',
clientSecret: 'secret',
token: {
url: "https://api.example.com/api/auth/socialite/google"
}
})
我添加了 token
选项,就像在这里定义的一样:https://next-auth.js.org/configuration/providers/oauth#token-option
并且添加了 jwt 回调:
async jwt({ token, account }) {
if (account) {
token.jwt = account.id_token
}
return token
}
一切都正常,包括 Google 授权等等。但在授权过程中,我期望进行 API 请求以从我的 Laravel 应用程序中获取 access_token
。account
参数中有一些 access_token
和 id_token
,但这些不是来自我的应用程序。
几年前,我在 Nuxt 2 中使用了一些不同的设置,像这样,并且它有效:
google: {
clientId: 'secret.apps.googleusercontent.com',
clientSecret: 'secret',
responseType: 'code',
codeChallengeMethod: '',
endpoints: {
token: 'https://api.example.com/api/auth/socialite/google'
},
token: {
property: 'access_token',
}
}
我是否正确使用了 token
选项?
英文:
I'm using nuxt 3.2.3
with @sidebase/nuxt-auth 0.5.0-rc.0
for authorization.
I defined Google Provider this way:
...
GoogleProvider.default({
clientId: 'secret.apps.googleusercontent.com',
clientSecret: 'secret',
token: {
url: "https://api.example.com/api/auth/socialite/google"
}
})
...
So I added token
option as it is defined here: https://next-auth.js.org/configuration/providers/oauth#token-option
And also jwt callback:
...
async jwt({ token, account }) {
if (account) {
token.jwt = account.id_token
}
return token
}
...
Everything works fine like Google authorization and so on, but in the process of authorization I would expect to make an API request to retrieve an access_token from my Laravel application. There are some access_token
and id_token
in account
parameter, but those are not from my application.
I did the same with Nuxt 2 few years ago with some different settings and it worked:
...
google: {
clientId: 'secret.apps.googleusercontent.com',
clientSecret: 'secret',
responseType: 'code',
codeChallengeMethod: '',
endpoints: {
token: 'https://api.example.com/api/auth/socialite/google'
},
token: {
property: 'access_token',
}
}
...
Am I using the token
option the right way?
答案1
得分: 1
After reading this article I found out the solution for my effort to connect Nuxt and nuxt-auth with separate API server.
我的后端应用程序的令牌可以在使用 signIn
回调时获取。不需要在Google提供程序中使用 token
选项。
英文:
After reading this article I found out the solution for my effort to connect Nuxt and nuxt-auth with separate API server.
The token from my backend application is possible to obtain using signIn
Callback. No need to use token
option in Google Provider.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论