I'm trying to setup an Oauth2 auth between my nuxt app and my PHP backend API.
Everything works fine until I try to fetch my user. I can't seem to configure my proxy right.
My api is https://api.local/api (on port 443)
My nuxt app is https://nuxt.local:8331
When I don't set any proxy, I have cors issues so I tried this :
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy',
'@nuxtjs/auth-next'
],
axios: {
proxy: true
},
proxy: {
'/api': {
target: 'https://api.local',
pathRewrite: {'^/api': '/api'},
changeOrigin: true
}
},
my auth configuration :
auth: {
redirect: {
login: '/login',
logout: '/logout',
home: '/',
},
strategies: {
my_strategy: {
scheme: 'oauth2',
endpoints: {
authorization: 'https://api.local/oauth2/auth',
token: 'https://api.local/oauth2/token',
userInfo: '/api/me/profile',
logout: 'https://api.local/oauth2/logout',
},
token: {
property: 'access_token',
type: 'Bearer',
maxAge: 1800
},
refreshToken: {
property: 'refresh_token',
maxAge: 60 * 60 * 24 * 30
},
responseType: 'code',
codeChallengeMethod: 'S256',
grantType: 'authorization_code',
accessType: undefined,
redirectUri: process.env.OAUTH2_REDIRECT_URI,
logoutRedirectUri: undefined,
clientId: process.env.API_KEY,
scope: [],
}
}
But when I call this.$auth.fetchUser() (when the token is set) I get this error :
Error occured while trying to proxy: nuxt.local:8331/api/me/profile
What am I doing wrong here ?