-
Notifications
You must be signed in to change notification settings - Fork 2
/
auth.js
75 lines (48 loc) · 1.59 KB
/
auth.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var credentials = require('./credentials.json')
var CLIENT_ID= credentials.client_id;
var CLIENT_SECRET=credentials.client_secret;
var REDIRECT_URL=credentials.redirect_url;
var Youtube = require("youtube-api");
var scopes = [
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.force-ssl',
'https://www.googleapis.com/auth/youtubepartner'
];
youtubeAuth = function(){
this.authObj = Youtube.authenticate({
type: "oauth"
, client_id: CLIENT_ID
, client_secret: CLIENT_SECRET
, redirect_url: REDIRECT_URL
});
this.authURL;
this.getAuthObject = function(){
return this.authObj;
}
this.getAuthURL = function(){
this.authURL = this.authObj.generateAuthUrl({
access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token)
scope: scopes // If you only need one scope you can pass it as string
});
return this.authURL;
}
this.getTokens = function(auth_code,cb){
this.authObj.getToken(auth_code,function(err,tokens){
cb(tokens);
});
}
this.getSubscriptions = function(resources,callback) {
Youtube.subscriptions.list(resources,function (err, data) {
callback(err,data);
});
}
this.setSubscription = function(resources,callback){
Youtube.subscriptions.insert({
part : "snippet",
resource : resources
},function(err,data){
callback(err,data);
});
}
};
module.exports = exports = new youtubeAuth();