Javascript 避免在HTML中公开LinkedIn API密钥

Javascript 避免在HTML中公开LinkedIn API密钥,javascript,node.js,express,oauth-2.0,linkedin-api,Javascript,Node.js,Express,Oauth 2.0,Linkedin Api,我希望我的用户使用LinkedIn登录功能登录。LinkedIn API文档提供了以下入门示例片段: <script type="text/javascript" src="//platform.linkedin.com/in.js"> api_key: YOUR_API_KEY_HERE authorize: true onLoad: onLinkedInLoad </script> <script type="text/javascri

我希望我的用户使用LinkedIn登录功能登录。LinkedIn API文档提供了以下入门示例片段:

<script type="text/javascript" src="//platform.linkedin.com/in.js">
    api_key: YOUR_API_KEY_HERE
    authorize: true
    onLoad: onLinkedInLoad
</script>

<script type="text/javascript">

    // Setup an event listener to make an API call once auth is complete
    function onLinkedInLoad() {
        IN.Event.on(IN, "auth", getProfileData);
    }

    // Handle the successful return from the API call
    function onSuccess(data) {
        console.log(data);
    }

    // Handle an error response from the API call
    function onError(error) {
        console.log(error);
    }

    // Use the API call wrapper to request the member's basic profile data
    function getProfileData() {
        IN.API.Raw("/people/~").result(onSuccess).error(onError);
    }

</script>

api_密钥:这里是您的api_密钥
授权:正确
onLoad:onLinkedInLoad
//设置事件侦听器,以便在完成身份验证后进行API调用
函数onLinkedInLoad(){
IN.Event.on(在“auth”中,getProfileData);
}
//处理API调用的成功返回
函数onSuccess(数据){
控制台日志(数据);
}
//处理来自API调用的错误响应
函数onError(错误){
console.log(错误);
}
//使用API调用包装器请求成员的基本配置文件数据
函数getProfileData(){
IN.API.Raw(“/people/~”).result(onSuccess).error(onError);
}
如何在不向公众公开您的API密钥的情况下实现此功能?有一些npm软件包可以处理这种事情,但它们都是旧的(每当一个软件包至少一年没有更新时,我就会感到紧张)


我的应用程序使用node和express。我应该使用旧的npm软件包,还是有更好的方法隐藏api密钥?

在javascript或网站中有您的api密钥是可以的,也是必要的,有时也是必要的。重要的一点是不要共享您的密钥,因为您需要两者都使用API来执行任何操作。确保所有通信始终使用HTTPS

从linkedin安全应用程序最佳实践网站:

API密钥和密钥

在调用LinkedIn API时,您使用两条可识别信息:API密钥(有时称为消费者密钥)和密钥(或消费者密钥)

API密钥是应用程序的公共标识符,密钥是机密的,只能用于在LinkedIn API上验证应用程序

由于确认应用程序的身份需要同时使用API密钥和密钥,因此决不公开密钥是至关重要的。以下是正确存储密钥的一些建议:

创建本机移动应用程序时,不要将其本地存储在移动设备上

不要在任何客户端代码文件(如JavaScript或HTML文件)中公开

不要将其存储在web服务器上可从外部查看的文件中,例如:配置文件、包含文件等

不要将其存储在日志文件或错误消息中

不要通过电子邮件或在留言板或其他公共论坛上发布

请记住,当用OAuth 2.0授权码交换访问令牌时,密钥作为请求的一部分传递。不要公开此请求