【问题标题】:Nuxt Apollo module request authorization header with double 'Bearer 'Nuxt Apollo 模块请求授权标头,带有双 'Bearer'
【发布时间】:2020-07-31 07:01:43
【问题描述】:

在我的 Nuxt 应用程序中,我将身份验证令牌存储在名为“auth._token.auth0”的 cookie 中。它看起来像:

Bearer%20eyJhbGciO...

我想在我的 apollo 请求授权标头中使用这个令牌,所以我配置了我的 apollo 模块:

apollo: {
    clientConfigs: {
        default: {
            httpEndpoint: process.env.GRAPHQL_ENDPOINT,
            httpLinkOptions: {
                credentials: 'same-origin'
            },
            tokenName: 'auth._token.auth0'
        }
    }
},

它成功地将 cookie 中的令牌附加到 apollo 授权标头,但它添加了另一个 'Bearer' 字符串,因此 graphql 返回 Malformed Authorization 标头错误,因为授权标头看起来像:

authorization: Bearer Bearer eyJhbGciOi...

任何想法如何在 nuxt apollo 模块或 nuxt auth 模块中解决这个问题?

【问题讨论】:

    标签: authentication token nuxt.js apollo auth0


    【解决方案1】:

    我通过在配置中添加authenticationType: '' 来修复它:

    apollo: {
        clientConfigs: {
            default: {
                httpEndpoint: process.env.GRAPHQL_ENDPOINT,
                httpLinkOptions: {
                    credentials: 'same-origin'
                },
                tokenName: 'auth._token.auth0'
            }
        },
        authenticationType: ''
    },
    

    【讨论】:

      猜你喜欢
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 2017-08-07
      • 1970-01-01
      • 2023-04-10
      • 2021-03-24
      • 2020-08-01
      相关资源
      最近更新 更多