开发者

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

开发者 https://www.devze.com 2023-02-11 21:41 出处:网络
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 s

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!


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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消