-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuth-assistant.js
90 lines (64 loc) · 2.28 KB
/
Auth-assistant.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var AuthAssistant=Class.create({
initialize: function(APIobj) {
this.authInfo={};
this.serviceAPI=APIobj;
this._handleAuthButton=this.handleAuthButton.bindAsEventListener(this);
this.serviceName=service;
},
setup: function() {
this.controller.get("AuthStatus").innerHTML=$L("Fetching Authentication Token");
this.spinnerModel= {
spinning: true,
spinnerSize: 'Mojo.Widget.spinnerSmall'
};
this.controller.setupWidget('authSpinner', this.spinnerModel);
this.authSpinner=this.controller.get('authSpinner');
this.controller.instantiateChildWidgets(this.authSpinner.up());
this.authSpinner.mojo.start();
switch (this.serviceName){
case 'picassa':
oauth={key: 'YOUR_KEY', secret: 'YOUR_SECRET', callback:"YOUR_CALLBACK"}
args={scope:"http://picasaweb.google.com/data/",xoauth_displayname:"APP_NAME"}
this.oauth=new OAuth('google',oauth,args,this,this.handleOAuth.bind(this));
break
case 'photobucket':
oauth={key: 'YOUR_KEY', secret: 'YOUR_SECRET', callback:"YOUR_CALLBACK"}
args={format:'json'}
this.oauth=new OAuth('photobucket',oauth,args,this,this.handleOAuth.bind(this));
}
},
handleOAuth: function(o) {
if (o.success) {
switch(o.service) {
case 'google':
this.authInfo.googleInfo={};
this.authInfo.googleInfo.token=o.token;
this.authInfo.googleInfo.secret=o.secret;
this.controller.stageController.popScene({ authenticated: true,service: o.service });
break
case 'photobucket':
this.authInfo.pbInfo={};
this.authInfo.pbInfo.token=o.token;
this.authInfo.pbInfo.secret=o.secret;
this.controller.stageController.popScene({ authenticated: true,service: o.service });
break
}
Mojo.Log.info('<<<<<<<Oauth Complete!!!')
}
else {
this.handleError(o);
}
},
handleError: function(o){
//Not informative, add a dialog or something appropriate for your app
Mojo.Log.error('<<<<<<Token Error>>>>>>')
},
activate: function(event) {
this.controller.listen('authOK',Mojo.Event.tap,this._handleAuthButton)
},
deactivate: function(event) {
this.controller.stopListening('authOK',Mojo.Event.tap,this._handleAuthButton)
},
cleanup: function(event) {
}
})