如何在 GitHub 中保存或安全避免 Facebook 或 LinkedIn 等社交网络的关键

How save or safately avoid the key of Social Networks like Facebook or LinkedIn in GitHub

出于 安全性 的原因,一些教程建议不要将密钥保存在 GitHub 中,他们将文件保存在 .gitignore 中,但例如一些 社交网络 喜欢FacebookLinkedinInfo.plist 文件中创建密钥。

Info.plist 包含应用程序的许多其他设置,必须提交。

我怎样才能安全我的密钥并正常提交Info.plist

Info.plist 示例(CFBundleURLSchemesFacebookAppID

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb355414950742780</string>
            </array>
        </dict>
    </array>
<key>FacebookAppID</key>
<string>355414950742780</string>

尝试不推送 Info.plist 文件风险太大。
版本更安全(git rm --cached <File>,并添加到.gitignore

然后你可以使用content filter driver, using using .gitattributes declaration:

注册一个smudge脚本,它将生成包含git checkout.

敏感信息的文件

(图片来自“Customizing Git - Git Attributes", from "Pro Git book”)

smudge”脚本(您必须编写)需要:

  • 获取密钥(从源外部回购,这样就没有错误添加和推送的风险)
  • 生成 Info.plist 文件,使用跟踪的 模板 Info.plist.tpl 替换其中的占位符值。

这意味着:

  • 模板 Info.plist.tpl 已添加到 git 存储库
  • 生成文件 Info.plist.gitignore 文件中声明并且从未版本化(也从未推送)。