@@ -27,6 +27,20 @@ function getAuthType() {
27
27
}
28
28
// [END apps_script_data_studio_get_auth_type_oauth2]
29
29
30
+ // [START apps_script_data_studio_get_auth_type_path_user_pass]
31
+ /**
32
+ * Returns the Auth Type of this connector.
33
+ * @return {object } The Auth type.
34
+ */
35
+ function getAuthType ( ) {
36
+ var cc = DataStudioApp . createCommunityConnector ( ) ;
37
+ return cc . newAuthTypeResponse ( )
38
+ . setAuthType ( cc . AuthType . PATH_USER_PASS )
39
+ . setHelpUrl ( 'https://www.example.org/connector-auth-help' )
40
+ . build ( ) ;
41
+ }
42
+ // [END apps_script_data_studio_get_auth_type_path_user_pass]
43
+
30
44
// [START apps_script_data_studio_get_auth_type_user_pass]
31
45
/**
32
46
* Returns the Auth Type of this connector.
@@ -91,6 +105,18 @@ function resetAuth() {
91
105
}
92
106
// [END apps_script_data_studio_auth_reset_oauth2]
93
107
108
+ // [START apps_script_data_studio_auth_reset_path_user]
109
+ /**
110
+ * Resets the auth service.
111
+ */
112
+ function resetAuth ( ) {
113
+ var userProperties = PropertiesService . getUserProperties ( ) ;
114
+ userProperties . deleteProperty ( 'dscc.path' ) ;
115
+ userProperties . deleteProperty ( 'dscc.username' ) ;
116
+ userProperties . deleteProperty ( 'dscc.password' ) ;
117
+ }
118
+ // [END apps_script_data_studio_auth_reset_path_user]
119
+
94
120
// [START apps_script_data_studio_auth_reset_user]
95
121
/**
96
122
* Resets the auth service.
@@ -133,6 +159,22 @@ function isAuthValid() {
133
159
}
134
160
// [END apps_script_data_studio_auth_valid_oauth2]
135
161
162
+ // [START apps_script_data_studio_auth_valid_path_user_pass]
163
+ /**
164
+ * Returns true if the auth service has access.
165
+ * @return {boolean } True if the auth service has access.
166
+ */
167
+ function isAuthValid ( ) {
168
+ var userProperties = PropertiesService . getUserProperties ( ) ;
169
+ var path = userProperties . getProperty ( 'dscc.path' ) ;
170
+ var userName = userProperties . getProperty ( 'dscc.username' ) ;
171
+ var password = userProperties . getProperty ( 'dscc.password' ) ;
172
+ // This assumes you have a validateCredentials function that
173
+ // can validate if the userName and password are correct.
174
+ return validateCredentials ( path , userName , password ) ;
175
+ }
176
+ // [END apps_script_data_studio_auth_valid_path_user_pass]
177
+
136
178
// [START apps_script_data_studio_auth_valid_user_pass]
137
179
/**
138
180
* Returns true if the auth service has access.
@@ -221,6 +263,38 @@ function get3PAuthorizationUrls() {
221
263
}
222
264
// [END apps_script_data_studio_auth_urls]
223
265
266
+ // [START apps_script_data_studio_auth_set_credentials_path_user_pass]
267
+ /**
268
+ * Sets the credentials.
269
+ * @param {Request } request The set credentials request.
270
+ * @return {object } An object with an errorCode.
271
+ */
272
+ function setCredentials ( request ) {
273
+ var creds = request . userPass ;
274
+ var path = creds . path ;
275
+ var username = creds . username ;
276
+ var password = creds . password ;
277
+
278
+ // Optional
279
+ // Check if the provided path, username and password are valid through
280
+ // a call to your service. You would have to have a `checkForValidCreds`
281
+ // function defined for this to work.
282
+ var validCreds = checkForValidCreds ( path , username , password ) ;
283
+ if ( ! validCreds ) {
284
+ return {
285
+ errorCode : 'INVALID_CREDENTIALS'
286
+ } ;
287
+ }
288
+ var userProperties = PropertiesService . getUserProperties ( ) ;
289
+ userProperties . setProperty ( 'dscc.path' , path ) ;
290
+ userProperties . setProperty ( 'dscc.username' , username ) ;
291
+ userProperties . setProperty ( 'dscc.password' , password ) ;
292
+ return {
293
+ errorCode : 'NONE'
294
+ } ;
295
+ }
296
+ // [END apps_script_data_studio_auth_set_credentials_path_user_pass]
297
+
224
298
// [START apps_script_data_studio_auth_set_credentials_user_pass]
225
299
/**
226
300
* Sets the credentials.
0 commit comments