【问题标题】:Nuxt Auth - hide client_secretNuxt Auth - 隐藏 client_secret
【发布时间】:2018-07-22 09:58:39
【问题描述】:

使用默认的 laravel.passport 策略时,我传递了client_secret,当我运行npm run generate 并在dist 中搜索生成的代码时,我找不到client_secret;它是隐藏的,这很好,也是我想要的。

但是,当我使用自定义策略或本地策略并传递client_secret 时,我可以在 dist 中看到生成的代码中的秘密。

  auth: {
    strategies: {
      password_grant_custom: {
        _scheme: "~/auth/schemes/PassportPasswordScheme.js",
        client_id: process.env.PASSPORT_PASSWORD_GRANT_ID,
        client_secret: process.env.PASSPORT_PASSWORD_GRANT_SECRET,
        endpoints: {
          login: {
            url: "/oauth/token",
            method: "post",
            propertyName: "access_token"
          },
          logout: false,
          user: {
            url: "api/v1/me",
            method: 'get',
            propertyName: false
          }
        }
      },
      'laravel.passport': {
        url: "https://example.com",
        client_id: process.env.PASSPORT_CLIENT_ID,
        client_secret: process.env.PASSPORT_CLIENT_SECRET,
        userinfo_endpoint: "https://example.com/api/v1/me",
      }
    }
  },

如何隐藏client_secret,使其在公共代码中不可见?

【问题讨论】:

    标签: vue.js oauth-2.0 nuxt.js


    【解决方案1】:

    因为在 laravel.passport 中它在调用 addAuthorize 时被删除。见code

      // Get client_secret, client_id and token_endpoint
      const clientSecret = strategy.client_secret
      const clientID = strategy.client_id
      const tokenEndpoint = strategy.token_endpoint
    
      // IMPORTANT: remove client_secret from generated bundle
      delete strategy.client_secret
    

    所以你需要为你的方案做同样的事情

    【讨论】:

    • 啊谢谢!因此,对于 constructor(auth, options) 函数,它会在函数的末尾以 delete options.client_secret 出现,对吗?这是我的source code
    • 嗯,将它添加到我在the scheme 的构造函数中不起作用...
    • @Michał 删除后你最终得到的确切代码是什么?因为如果你只是删除你将无法在 this.options.client_secret 中进一步访问
    • By 不起作用,我的意思是当我在自定义方案中将delete options.client_secret 添加到构造函数的末尾时,它没有删除任何内容。 addAuthorize 似乎在提供者级别而不是方案级别...
    • @Michał 我的意思是你确实分配给了 this.options。如果你只是从选项 arg 中删除它,它仍然会在 this.options 中
    猜你喜欢
    • 2018-12-05
    • 2017-08-01
    • 1970-01-01
    • 2020-06-11
    • 2021-08-15
    • 2021-09-15
    • 2022-01-26
    • 2019-02-21
    • 1970-01-01
    相关资源
    最近更新 更多