@@ -26,6 +26,16 @@ function getAuthType() {
2626function getAuthType ( ) {
2727 return {
2828 "type" : "USER_PASS"
29+ "helpUrl" : "https://www.example.org/connector-auth-help"
30+ } ;
31+ }
32+ // [END apps_script_data_studio_get_auth_type_user_pass]
33+
34+ // [START apps_script_data_studio_get_auth_type_user_token]
35+ function getAuthType ( ) {
36+ return {
37+ "type" : "USER_TOKEN"
38+ "helpUrl" : "https://www.example.org/connector-auth-help"
2939 } ;
3040}
3141// [END apps_script_data_studio_get_auth_type_user_pass]
@@ -34,6 +44,7 @@ function getAuthType() {
3444function getAuthType ( ) {
3545 return {
3646 "type" : "KEY"
47+ "helpUrl" : "https://www.example.org/connector-auth-help"
3748 } ;
3849}
3950// [END apps_script_data_studio_get_auth_type_key]
@@ -60,6 +71,14 @@ function resetAuth() {
6071}
6172// [END apps_script_data_studio_auth_reset_user]
6273
74+ // [START apps_script_data_studio_auth_reset_user_token]
75+ function resetAuth ( ) {
76+ var user_tokenProperties = PropertiesService . getUserProperties ( ) ;
77+ user_tokenProperties . deleteProperty ( 'dscc.username' ) ;
78+ user_tokenProperties . deleteProperty ( 'dscc.password' ) ;
79+ }
80+ // [END apps_script_data_studio_auth_reset_user_token]
81+
6382// [START apps_script_data_studio_auth_reset_key]
6483function resetAuth ( ) {
6584 var userProperties = PropertiesService . getUserProperties ( ) ;
@@ -84,6 +103,18 @@ function isAuthValid() {
84103}
85104// [END apps_script_data_studio_auth_valid_user_pass]
86105
106+
107+ // [START apps_script_data_studio_auth_valid_user_token]
108+ function isAuthValid ( ) {
109+ var userProperties = PropertiesService . getUserProperties ( ) ;
110+ var userName = userProperties . getProperty ( 'dscc.username' ) ;
111+ var token = userProperties . getProperty ( 'dscc.token' ) ;
112+ // This assumes you have a validateCredentials function that
113+ // can validate if the userName and token are correct.
114+ return validateCredentials ( userName , token ) ;
115+ }
116+ // [END apps_script_data_studio_auth_valid_user_token]
117+
87118// [START apps_script_data_studio_auth_valid_key]
88119function isAuthValid ( ) {
89120 var userProperties = PropertiesService . getUserProperties ( ) ;
@@ -149,6 +180,31 @@ function setCredentials(request) {
149180}
150181// [END apps_script_data_studio_auth_set_credentials_user_pass]
151182
183+ // [START apps_script_data_studio_auth_set_credentials_user_token]
184+ function setCredentials ( request ) {
185+ var creds = request . userToken ;
186+ var username = creds . username ;
187+ var token = creds . token ;
188+
189+ // Optional
190+ // Check if the provided username and token are valid through a
191+ // call to your service. You would have to have a `checkForValidCreds`
192+ // function defined for this to work.
193+ var validCreds = checkForValidCreds ( username , token ) ;
194+ if ( ! validCreds ) {
195+ return {
196+ errorCode : "INVALID_CREDENTIALS"
197+ } ;
198+ }
199+ var userProperties = PropertiesService . getUserProperties ( ) ;
200+ userProperties . setProperty ( 'dscc.username' , username ) ;
201+ userProperties . setProperty ( 'dscc.token' , token ) ;
202+ return {
203+ errorCode : "NONE"
204+ } ;
205+ }
206+ // [END apps_script_data_studio_auth_set_credentials_user_token]
207+
152208// [START apps_script_data_studio_auth_set_credentials_key]
153209function setCredentials ( request ) {
154210 var key = request . key ;
0 commit comments