What is the best to identify machine/user in Google Chrome Extention?

一个人想着一个人 提交于 2020-01-02 07:31:32

问题


I have a web app and complementing chrome extension for it, which sends data in background to the web app. Now, I want to send this data to the corresponding user account in the web app. What method should I use? How should I handle the authentication?

I was thinking if there was some way to identify machine ID or something which I can register while user is signing up, but I cannot see any method to get machine ID.

Please suggest a best way to implement this.

Thanks!


回答1:


Here is what I am doing in my extension where I need to track machines.

var macId = null;
chrome.storage.local.get('machine-id', function(item){
  var storedMacId = item['machine-id'];
  if(!storedMacId) {
    storedMacId = Math.random().toString(36).slice(2);
    chrome.storage.local.set({'machine-id':storedMacId});
  }
  macId = storedMacId;
});

Basically, I assign a random string to my macId variable and store it in the local session. You could potentially associate with a user and use it to track different installs. If you want to track all installs by the same user as one, you can replace local with sync (it syncs across all chrome browsers signed in with the users google id).

Hope this answers your question.

Cheers!




回答2:


As far as I know this is done using an API key. Most web based APIs use this method for authentication. You can have it generated when user signs up and also provide the user the option of re-generating it. Take a look at this api for example. It is a URL shortening service which authenticates users by an API key.




回答3:


OAuth is pretty much the standard method of authentication for web app APIs these days.



来源:https://stackoverflow.com/questions/5051224/what-is-the-best-to-identify-machine-user-in-google-chrome-extention

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!