कम्यूनिटी कनेक्टर में पुष्टि करने के इन तरीकों का इस्तेमाल किया जा सकता है:
- 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
KEY
कोई नहीं
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
KEY
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
KEY
OAUTH2
'ऐप्लिकेशन स्क्रिप्ट लाइब्रेरी' के लिए OAuth2 को जोड़ना और सेटअप करना
'Apps स्क्रिप्ट लाइब्रेरी के लिए OAuth2' के सेटअप के निर्देशों का पालन करके, इसे अपने कनेक्टर प्रोजेक्ट में जोड़ें. इसके बाद, अपने कनेक्टर प्रोजेक्ट में OAuth2 सेवा बनाने के लिए, इस्तेमाल के बारे में गाइड में दिए गए पहले चरण का पालन करें. आपकी OAuth2 सेवा में कोई भी मान्य फ़ंक्शन नाम हो सकता है, लेकिन अपने कोड में OAuth2 सेवा का हवाला देते समय पक्का करें कि उसी नाम का इस्तेमाल किया जा रहा हो.
उदाहरण के लिए, exampleService
नाम की OAuth2 सेवा:
authCallback()
इस फ़ंक्शन को OAuth 2.0 फ़्लो को पूरा करने के लिए कॉल किया जाता है. तीसरे पक्ष की पुष्टि करने वाली सेवा से मिला कॉलबैक रिस्पॉन्स, तर्क के तौर पर दिया जाता है और इसे यह फ़ंक्शन मैनेज करता है.
'Apps स्क्रिप्ट लाइब्रेरी के लिए 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
को कॉल किया जाता है. आपको 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'
};
}