-
Notifications
You must be signed in to change notification settings - Fork 1
/
oauth.js
30 lines (27 loc) · 1.07 KB
/
oauth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function OAuth(config) {
this.request_uri = config['request_url'];
this.authorize_url=config['authorize_url'];
this.access_url=config['access_url'];
this.consumer_key=config['consumer_key'];
this.redirect_url = config['redirect_url'];
this.authorize = function() {
var url = this.request_uri;
//Content-Type: application/json; charset=UTF8
var headers = [];
headers.push({"name":"Content-Type","value":"application/json; charset=UTF8"});
var body = '{"consumer_key":"'+this.consumer_key+'","redirect_uri":"'+this.redirect_url+'"}';
var response = fetch(url,"POST",headers,body,null,false,false);
response = response.split("=")[1];
localStorage["request_token"]=response;
var url = "https://getpocket.com/auth/authorize?request_token="+response+"&redirect_uri="+this.redirect_url;
console.log(url);
chrome.tabs.create({"url":url});
}
this.isAuthorized = function() {
if (localStorage["access_token4"]) return true;
return false;
}
this.getAuthToken = function() {
return localStorage["access_token4"];
}
}