कम्यूनिटी कनेक्टर, पुष्टि करने के लिए यहां दिए गए तरीके इस्तेमाल कर सकते हैं:
- OAuth 2.0
- पाथ/उपयोगकर्ता नाम/पासवर्ड
- पाथ/कुंजी
- उपयोगकर्ता नाम/पासवर्ड
- उपयोगकर्ता नाम/टोकन
- कुंजी
- कोई नहीं
आपने जिस तरीके का इस्तेमाल किया है उसके हिसाब से, आपको अपने कनेक्टर में अतिरिक्त फ़ंक्शन देने होंगे.
नीचे दी गई टेबल में बताया गया है कि आपको अपने कनेक्टर के पुष्टि करने के तरीके के आधार पर, कौनसे फ़ंक्शन तय करने होंगे.
OAUTH2 | PATH_USER_PASS PATH_KEY USER_PASS USER_TOKEN KEY |
कोई नहीं | |
---|---|---|---|
getAuthType() |
ज़रूरी है | ज़रूरी है | ज़रूरी है |
resetAuth() |
ज़रूरी है | ज़रूरी है | |
isAuthValid() |
ज़रूरी है | ज़रूरी है | |
authCallback() |
ज़रूरी है | ||
get3PAuthorizationUrls() |
ज़रूरी है | ||
setCredentials() |
ज़रूरी है |
getAuthType()
इस फ़ंक्शन को कनेक्टर के लिए पुष्टि करने का टाइप दिखाना चाहिए.
OAUTH2
PATH_USER_PASS
/**
* Returns the Auth Type of this connector.
* @return {object} The Auth type.
*/
function getAuthType() {
var cc = DataStudioApp.createCommunityConnector();
return cc.newAuthTypeResponse()
.setAuthType(cc.AuthType.PATH_USER_PASS)
.setHelpUrl('https://www.example.org/connector-auth-help')
.build();
}
PATH_KEY
/**
* Returns the Auth Type of this connector.
* @return {object} The Auth type.
*/
function getAuthType() {
var cc = DataStudioApp.createCommunityConnector();
return cc.newAuthTypeResponse()
.setAuthType(cc.AuthType.PATH_KEY)
.setHelpUrl('https://www.example.org/connector-auth-help')
.build();
}
USER_PASS
USER_TOKEN
कुंजी
कोई नहीं
resetAuth()
यह फ़ंक्शन, तीसरे पक्ष की सेवा के लिए उपयोगकर्ता के सेव किए गए सभी क्रेडेंशियल मिटा देगा.
OAUTH2
PATH_USER_PASS
/**
* Resets the auth service.
*/
function resetAuth() {
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('dscc.path');
userProperties.deleteProperty('dscc.username');
userProperties.deleteProperty('dscc.password');
}
PATH_KEY
/**
* Resets the auth service.
*/
function resetAuth() {
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('dscc.path');
userProperties.deleteProperty('dscc.key');
}
USER_PASS
USER_TOKEN
कुंजी
isAuthValid()
इस फ़ंक्शन को यह पता लगाने के लिए कॉल किया जाता है कि तीसरे पक्ष की सेवा के लिए पुष्टि मान्य है या नहीं. अगर पुष्टि मान्य है, तो उम्मीद है कि अनधिकृत ऐक्सेस की वजह से getData()
और getSchema()
को किए गए कॉल फ़ेल नहीं होंगे. अगर पुष्टि मान्य नहीं है, तो उपयोगकर्ता को पुष्टि करने का फ़्लो शुरू करने के लिए सूचना मिल सकती है.
OAUTH2
PATH_USER_PASS
/**
* Returns true if the auth service has access.
* @return {boolean} True if the auth service has access.
*/
function isAuthValid() {
var userProperties = PropertiesService.getUserProperties();
var path = userProperties.getProperty('dscc.path');
var userName = userProperties.getProperty('dscc.username');
var password = userProperties.getProperty('dscc.password');
// This assumes you have a validateCredentials function that
// can validate if the path, userName and password are correct.
return validateCredentials(path, userName, password);
}
PATH_KEY
/**
* Returns true if the auth service has access.
* @return {boolean} True if the auth service has access.
*/
function isAuthValid() {
var userProperties = PropertiesService.getUserProperties();
var path = userProperties.getProperty('dscc.path');
var key = userProperties.getProperty('dscc.key');
// This assumes you have a validateCredentials function that
// can validate if the path and key are correct.
return validateCredentials(path, key);
}
USER_PASS
USER_TOKEN
कुंजी
OAUTH2
Apps Script लाइब्रेरी के लिए OAuth2 को जोड़ना और सेट अप करना
Apps Script के लिए OAuth2 लाइब्रेरी को अपने कनेक्टर प्रोजेक्ट में जोड़ने के लिए, सेटअप करने के निर्देशों का पालन करें. इसके बाद, अपने कनेक्टर प्रोजेक्ट में OAuth2 सेवा बनाने के लिए, इस्तेमाल से जुड़ी गाइड में दिया गया पहला चरण पूरा करें. आपकी OAuth2 सेवा के लिए, किसी भी मान्य फ़ंक्शन के नाम का इस्तेमाल किया जा सकता है. हालांकि, यह पक्का करें कि कोड में OAuth2 सेवा का रेफ़रंस देते समय, उसी नाम का इस्तेमाल किया गया हो.
उदाहरण के लिए, exampleService
नाम की OAuth2 सेवा:
authCallback()
OAuth 2.0 फ़्लो को पूरा करने के लिए, इस फ़ंक्शन को कॉल किया जाता है. तीसरे पक्ष की पुष्टि करने वाली सेवा से मिला कॉलबैक रिस्पॉन्स, आर्ग्युमेंट के तौर पर दिया जाता है. इस फ़ंक्शन को इसे हैंडल करना चाहिए.
Apps Script के लिए OAuth2 लाइब्रेरी का इस्तेमाल करके, OAuth 2.0 कॉलबैक को हैंडल करने का उदाहरण:
get3PAuthorizationUrls()
इस फ़ंक्शन को कॉल करके, उस यूआरएल को पाया जाता है जिसकी ज़रूरत तीसरे पक्ष की सेवा के लिए पुष्टि करने की प्रोसेस शुरू करने के लिए होती है. अगर isAuthValid
, false
दिखाता है, तो उपयोगकर्ता को बटन या लिंक के तौर पर यूआरएल दिखेगा, ताकि वह तीसरे पक्ष की सेवा को ऐक्सेस करने की अनुमति दे सके. get3PAuthorizationUrls() के बारे में जानकारी देने वाला रेफ़रंस देखें.
Apps Script के लिए OAuth2 लाइब्रेरी का इस्तेमाल करके, ऑथराइज़ेशन यूआरएल वापस पाने का उदाहरण:
USER_PASS
, USER_TOKEN
, KEY
, PATH_USER_PASS
, और PATH_KEY
नीचे दी गई जानकारी सिर्फ़ USER_PASS
, USER_TOKEN
, KEY
, PATH_USER_PASS
, और PATH_KEY
की पुष्टि करने के लिए ज़रूरी है.
setCredentials()
setCredentials
को तब कॉल किया जाता है, जब उपयोगकर्ता कम्यूनिटी कनेक्टर के कॉन्फ़िगरेशन पेज पर अपनी क्रेडेंशियल की जानकारी डालता है. आपको Properties Service का इस्तेमाल करना चाहिए, ताकि हर उपयोगकर्ता के लिए क्रेडेंशियल सेव किए जा सकें. इसके लिए, UserProperties
का इस्तेमाल करें.
PATH_USER_PASS
/**
* Sets the credentials.
* @param {Request} request The set credentials request.
* @return {object} An object with an errorCode.
*/
function setCredentials(request) {
var creds = request.pathUserPass;
var path = creds.path;
var username = creds.username;
var password = creds.password;
// Optional
// Check if the provided path, username and password are valid through
// a call to your service. You would have to have a `checkForValidCreds`
// function defined for this to work.
var validCreds = checkForValidCreds(path, username, password);
if (!validCreds) {
return {
errorCode: 'INVALID_CREDENTIALS'
};
}
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('dscc.path', path);
userProperties.setProperty('dscc.username', username);
userProperties.setProperty('dscc.password', password);
return {
errorCode: 'NONE'
};
}
PATH_KEY
/**
* Sets the credentials.
* @param {Request} request The set credentials request.
* @return {object} An object with an errorCode.
*/
function setCredentials(request) {
var creds = request.pathKey;
var path = creds.path;
var key = creds.key;
// Optional
// Check if the provided path and key are valid through
// a call to your service. You would have to have a `checkForValidCreds`
// function defined for this to work.
var validCreds = checkForValidCreds(path, key);
if (!validCreds) {
return {
errorCode: 'INVALID_CREDENTIALS'
};
}
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('dscc.path', path);
userProperties.setProperty('dscc.key', key);
return {
errorCode: 'NONE'
};
}