-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle.html
185 lines (174 loc) · 8.27 KB
/
google.html
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!--
/*******************************************************************************
* Copyright (C) 2018 Orange.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Rombit - initial API and implementation
******************************************************************************/
-->
<script type="text/x-red" data-template-name="google-credentials" data-lang="en-US">
<div id="node-config-google-client-keys">
<div class="form-row">
<p style="margin-top: 10px;"><b>1.</b> <span data-i18n="google.label.create"></span> <a href="https://developers.google.com/api-client-library/javascript/start/start-js#Getkeysforyourapplication" target="_blank" style="text-decoration:underline;"><span data-i18n="google.label.instructions"></span></a></p>
</div>
<div class="form-tips" id="node-config-google-tooltip">
</div>
<div class="form-row">
<p style="margin-top: 10px;"><b>2.</b> <span data-i18n="google.label.copy"></span>:</p>
</div>
<div class="form-row">
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-clientId"><i class="fa fa-user"></i> <span data-i18n="google.label.clientid"></span></label>
<input type="password" id="node-config-input-clientId">
</div>
<div class="form-row">
<label style="margin-left: 10px; margin-right: -10px;" for="node-config-input-clientSecret"><i class="fa fa-key"></i> <span data-i18n="google.label.secret"></span></label>
<input type="password" id="node-config-input-clientSecret">
</div>
<div class="form-row">
<label> </label>
<a class="btn" id="node-config-start-auth" href="#" target="_blank"><span data-i18n="google.label.authenticate"></span></a>
</div>
</div>
<div id="node-config-google">
<div class="form-row">
<label><i class="fa fa-user"></i> <span data-i18n="google.label.googleuser"></span></label><span id="node-config-google-displayName" class="input-xlarge uneditable-input"></span>
</div>
<input type="hidden" id="node-config-input-displayName">
</div>
</script>
<script type="text/javascript" data-lang="en-US">
(function() {
RED.nodes.registerType('google-credentials',{
category: 'config',
defaults: {
displayName: {value:""}
},
credentials: {
displayName: {type:"text"},
clientId: { type: "password"},
clientSecret: { type: "password"}
},
label: function() {
return this.displayName || this._("google.label.google"); // TODO: fix this
},
exportable: false,
oneditprepare: function() {
var id = this.id;
var pathname = document.location.pathname;
if (pathname.slice(-1) != "/") {
pathname += "/";
}
var privateIPRegex = /(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/;
var callback;
var tip;
if(privateIPRegex.test(location.hostname)) { // if private IP has been detected
var dummyDomain = "node-red.example.com";
var actualIP = location.hostname;
callback = location.protocol + "//" +
dummyDomain +
(location.port?":"+location.port:"")+
pathname + "google-credentials/auth/callback";
tip = this._("google.tip.privateip", {callback: callback, dummyDomain: dummyDomain, actualIP: actualIP});
$("#node-config-google-tooltip").html(tip);
} else {
callback = location.protocol + "//" +
location.hostname +
(location.port?":"+location.port:"")+
pathname + "google-credentials/auth/callback";
tip = this._("google.tip.configure", {callback: callback});
$("#node-config-google-tooltip").html(tip);
}
function updateGoogleAuthButton() {
var v1 = $("#node-config-input-clientId").val();
var v2 = $("#node-config-input-clientSecret").val();
$("#node-config-start-auth").toggleClass("disabled",(v1.length === 0 || v2.length === 0));
}
$("#node-config-input-clientId").on('change keydown paste input',updateGoogleAuthButton);
$("#node-config-input-clientSecret").on('change keydown paste input',updateGoogleAuthButton);
function updateGoogleDisplayName(dn) {
$("#node-config-google-client-keys").hide();
$("#node-config-google").show();
$("#node-config-input-displayName").val(dn);
$("#node-config-google-displayName").html(dn);
}
function pollGoogleCredentials() {
$.getJSON('credentials/google-credentials/'+id,function(data) {
if (data.displayName) {
$("#node-config-dialog-ok").button("enable");
updateGoogleDisplayName(data.displayName);
delete window.googleConfigNodeIntervalId;
} else {
window.googleConfigNodeIntervalId = window.setTimeout(pollGoogleCredentials,2000);
}
});
}
updateGoogleAuthButton();
if (this.displayName) {
updateGoogleDisplayName(this.displayName);
} else {
$("#node-config-google-client-keys").show();
$("#node-config-google").hide();
$("#node-config-dialog-ok").button("disable");
}
$("#node-config-start-auth").mousedown(function() {
var clientId = $("#node-config-input-clientId").val();
var clientSecret = $("#node-config-input-clientSecret").val();
var url = 'google-credentials/auth?id='+id+'&clientId='+clientId+"&clientSecret="+clientSecret+"&callback="+encodeURIComponent(callback);
$(this).attr("href",url);
window.googleConfigNodeIntervalId = window.setTimeout(pollGoogleCredentials,2000);
});
$("#node-config-start-auth").click(function(e) {
var clientId = $("#node-config-input-clientId").val();
var clientSecret = $("#node-config-input-clientSecret").val();
if (clientId === "" || clientSecret === "") {
e.preventDefault();
}
});
},
oneditsave: function() {
if (window.googleConfigNodeIntervalId) {
window.clearTimeout(window.googleConfigNodeIntervalId);
delete window.googleConfigNodeIntervalId;
}
},
oneditcancel: function() {
if (window.googleConfigNodeIntervalId) {
window.clearTimeout(window.googleConfigNodeIntervalId);
delete window.googleConfigNodeIntervalId;
}
}
});
})();
</script>
<script type="text/x-red" data-template-name="google-api-config" data-lang="en-US">
<div class="form-row">
<label for="node-config-input-key"><i class="fa fa-bookmark"></i><span data-i18n="google.label.apikey"></span></label>
<input class="input-append-left" type="password" id="node-config-input-key" style="width: 40%;" >
</div>
<div class="form-tips">
<span data-i18n="[html]google.tip.api1"></span>
<span data-i18n="[html]google.tip.api2"></span>
<span data-i18n="[html]google.tip.api3"></span>
</div>
</script>
<script type="text/javascript" data-lang="en-US">
(function() {
RED.nodes.registerType('google-api-config',{
category: 'config',
defaults: { },
credentials: {
key: {type: "password",required:true},
},
label: function() {
return this._("google.label.googleapi");
},
exportable: false,
});
})();
</script>