প্রমাণীকরণ

সম্প্রদায় সংযোগকারী নিম্নলিখিত প্রমাণীকরণ পদ্ধতি সমর্থন করে:

  • OAuth 2.0
  • পথ/ব্যবহারকারীর নাম/পাসওয়ার্ড
  • পথ/কী
  • ব্যবহারকারীর নাম/পাসওয়ার্ড
  • ব্যবহারকারীর নাম/টোকেন
  • চাবি
  • কোনোটিই নয়

আপনি কোন পদ্ধতি ব্যবহার করছেন তার উপর নির্ভর করে, আপনাকে অবশ্যই আপনার সংযোগকারীতে অতিরিক্ত ফাংশন প্রদান করতে হবে।

নিম্নলিখিত সারণীটি নির্দেশ করে যে আপনার সংযোগকারীর প্রমাণীকরণ প্রকারের উপর নির্ভর করে আপনাকে কোন ফাংশনগুলিকে সংজ্ঞায়িত করতে হবে।

OAUTH2 PATH_USER_PASS
PATH_KEY
USER_PASS
USER_TOKEN
চাবি
কোনটিই নয়
getAuthType() প্রয়োজনীয় প্রয়োজনীয় প্রয়োজনীয়
resetAuth() প্রয়োজনীয় প্রয়োজনীয়
isAuthValid() প্রয়োজনীয় প্রয়োজনীয়
authCallback() প্রয়োজনীয়
get3PAuthorizationUrls() প্রয়োজনীয়
setCredentials() প্রয়োজনীয়

getAuthType()

এই ফাংশনটি সংযোগকারীর জন্য প্রমাণীকরণের ধরণ প্রদান করবে।

OAUTH2

data-studio/auth.gs
/**
 * Returns the Auth Type of this connector.
 * @return {object} The Auth type.
 */
function getAuthType() {
  var cc = DataStudioApp.createCommunityConnector();
  return cc.newAuthTypeResponse()
      .setAuthType(cc.AuthType.OAUTH2)
      .build();
}

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

data-studio/auth.gs
/**
 * Returns the Auth Type of this connector.
 * @return {object} The Auth type.
 */
function getAuthType() {
  var cc = DataStudioApp.createCommunityConnector();
  return cc.newAuthTypeResponse()
      .setAuthType(cc.AuthType.USER_PASS)
      .setHelpUrl('https://www.example.org/connector-auth-help')
      .build();
}

USER_TOKEN

data-studio/auth.gs
/**
 * Returns the Auth Type of this connector.
 * @return {object} The Auth type.
 */
function getAuthType() {
  var cc = DataStudioApp.createCommunityConnector();
  return cc.newAuthTypeResponse()
      .setAuthType(cc.AuthType.USER_TOKEN)
      .setHelpUrl('https://www.example.org/connector-auth-help')
      .build();
}

চাবি

data-studio/auth.gs
/**
 * Returns the Auth Type of this connector.
 * @return {object} The Auth type.
 */
function getAuthType() {
  var cc = DataStudioApp.createCommunityConnector();
  return cc.newAuthTypeResponse()
      .setAuthType(cc.AuthType.KEY)
      .setHelpUrl('https://www.example.org/connector-auth-help')
      .build();
}

কোনটিই নয়

data-studio/auth.gs
/**
 * Returns the Auth Type of this connector.
 * @return {object} The Auth type.
 */
function getAuthType() {
  var cc = DataStudioApp.createCommunityConnector();
  return cc.newAuthTypeResponse()
      .setAuthType(cc.AuthType.NONE)
      .build();
}

resetAuth()

এই ফাংশনটি তৃতীয় পক্ষের পরিষেবার জন্য ব্যবহারকারীর জন্য সংরক্ষিত যেকোনো শংসাপত্র সাফ করবে।

OAUTH2

data-studio/auth.gs
/**
 * Resets the auth service.
 */
function resetAuth() {
  getOAuthService().reset();
}

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

data-studio/auth.gs
/**
 * Resets the auth service.
 */
function resetAuth() {
  var userProperties = PropertiesService.getUserProperties();
  userProperties.deleteProperty('dscc.username');
  userProperties.deleteProperty('dscc.password');
}

USER_TOKEN

data-studio/auth.gs
/**
 * Resets the auth service.
 */
function resetAuth() {
  var userTokenProperties = PropertiesService.getUserProperties();
  userTokenProperties.deleteProperty('dscc.username');
  userTokenProperties.deleteProperty('dscc.password');
}

চাবি

data-studio/auth.gs
/**
 * Resets the auth service.
 */
function resetAuth() {
  var userProperties = PropertiesService.getUserProperties();
  userProperties.deleteProperty('dscc.key');
}

isAuthValid()

তৃতীয় পক্ষের পরিষেবার জন্য প্রমাণীকরণ বৈধ কিনা তা নির্ধারণ করতে এই ফাংশনটি বলা হয়। যদি প্রমাণীকরণ বৈধ হয় তবে এটি আশা করা যায় যে অননুমোদিত অ্যাক্সেসের কারণে getData() এবং getSchema() এ কলগুলি ব্যর্থ হবে না। যদি প্রমাণীকরণ বৈধ না হয় তাহলে ব্যবহারকারী অনুমোদন প্রবাহ শুরু করার জন্য একটি বিজ্ঞপ্তি পেতে পারেন।

OAUTH2

data-studio/auth.gs
/**
 * Returns true if the auth service has access.
 * @return {boolean} True if the auth service has access.
 */
function isAuthValid() {
  return getOAuthService().hasAccess();
}

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

data-studio/auth.gs
/**
 * Returns true if the auth service has access.
 * @return {boolean} True if the auth service has access.
 */
function isAuthValid() {
  var userProperties = PropertiesService.getUserProperties();
  var userName = userProperties.getProperty('dscc.username');
  var password = userProperties.getProperty('dscc.password');
  // This assumes you have a validateCredentials function that
  // can validate if the userName and password are correct.
  return validateCredentials(userName, password);
}

USER_TOKEN

data-studio/auth.gs
/**
 * Returns true if the auth service has access.
 * @return {boolean} True if the auth service has access.
 */
function isAuthValid() {
  var userProperties = PropertiesService.getUserProperties();
  var userName = userProperties.getProperty('dscc.username');
  var token = userProperties.getProperty('dscc.token');
  // This assumes you have a validateCredentials function that
  // can validate if the userName and token are correct.
  return validateCredentials(userName, token);
}

চাবি

data-studio/auth.gs
/**
 * Returns true if the auth service has access.
 * @return {boolean} True if the auth service has access.
 */
function isAuthValid() {
  var userProperties = PropertiesService.getUserProperties();
  var key = userProperties.getProperty('dscc.key');
  // This assumes you have a validateKey function that can validate
  // if the key is valid.
  return validateKey(key);
}

OAUTH2

অ্যাপস স্ক্রিপ্ট লাইব্রেরির জন্য OAuth2 যোগ করুন এবং সেটআপ করুন

আপনার সংযোগকারী প্রকল্পে এটি যোগ করতে Apps স্ক্রিপ্ট লাইব্রেরির জন্য OAuth2 এর সেটআপ নির্দেশাবলী অনুসরণ করুন। তারপর আপনার সংযোগকারী প্রকল্পে একটি OAuth2 পরিষেবা তৈরি করতে ব্যবহারের নির্দেশিকাতে প্রথম ধাপ অনুসরণ করুন৷ আপনার OAuth2 পরিষেবার কোনও বৈধ ফাংশনের নাম থাকতে পারে তবে আপনার কোডে OAuth2 পরিষেবা উল্লেখ করার সময় একই নাম ব্যবহার করা নিশ্চিত করুন৷

উদাহরণস্বরূপ, exampleService নামে একটি OAuth2 পরিষেবা:

data-studio/auth.gs
/**
 * Returns the configured OAuth Service.
 * @return {Service} The OAuth Service
 */
function getOAuthService() {
  return OAuth2.createService('exampleService')
      .setAuthorizationBaseUrl('...')
      .setTokenUrl('...')
      .setClientId('...')
      .setClientSecret('...')
      .setPropertyStore(PropertiesService.getUserProperties())
      .setCallbackFunction('authCallback')
      .setScope('...');
};

authCallback()

এই ফাংশনটিকে OAuth 2.0 ফ্লো সম্পূর্ণ করতে বলা হয়। তৃতীয় পক্ষের প্রমাণীকরণ পরিষেবা থেকে কলব্যাক প্রতিক্রিয়া একটি যুক্তি হিসাবে প্রদান করা হয় এবং এই ফাংশন দ্বারা পরিচালনা করা উচিত।

Apps স্ক্রিপ্ট লাইব্রেরির জন্য OAuth2 ব্যবহার করে OAuth 2.0 কলব্যাক পরিচালনার উদাহরণ:

data-studio/auth.gs
/**
 * The OAuth callback.
 * @param {object} request The request data received from the OAuth flow.
 * @return {HtmlOutput} The HTML output to show to the user.
 */
function authCallback(request) {
  var authorized = getOAuthService().handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput('Success! You can close this tab.');
  } else {
    return HtmlService.createHtmlOutput('Denied. You can close this tab');
  };
};

get3PAuthorizationUrls()

তৃতীয় পক্ষের পরিষেবার জন্য প্রমাণীকরণ প্রবাহ শুরু করার জন্য প্রয়োজনীয় URL পেতে এই ফাংশনটিকে বলা হয়৷ যদি isAuthValid false ফেরত দেয় তাহলে ফেরত দেওয়া URLটি ব্যবহারকারীর কাছে একটি বোতাম বা লিঙ্ক হিসাবে প্রদর্শিত হবে যাতে তারা তৃতীয় পক্ষের পরিষেবাতে অ্যাক্সেস অনুমোদন করতে পারে। get3PAuthorizationUrls() এর জন্য রেফারেন্স দেখুন।

Apps স্ক্রিপ্ট লাইব্রেরির জন্য OAuth2 ব্যবহার করে অনুমোদন Url ফেরত দেওয়ার উদাহরণ:

data-studio/auth.gs
/**
 * Gets the 3P authorization URL.
 * @return {string} The authorization URL.
 * @see https://developers.google.com/apps-script/reference/script/authorization-info
 */
function get3PAuthorizationUrls() {
  return getOAuthService().getAuthorizationUrl();
}

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'
  };
}

USER_PASS

data-studio/auth.gs
/**
 * Sets the credentials.
 * @param {Request} request The set credentials request.
 * @return {object} An object with an errorCode.
 */
function setCredentials(request) {
  var creds = request.userPass;
  var username = creds.username;
  var password = creds.password;

  // Optional
  // Check if the provided 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(username, password);
  if (!validCreds) {
    return {
      errorCode: 'INVALID_CREDENTIALS'
    };
  }
  var userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty('dscc.username', username);
  userProperties.setProperty('dscc.password', password);
  return {
    errorCode: 'NONE'
  };
}

USER_TOKEN

data-studio/auth.gs
/**
 * Sets the credentials.
 * @param {Request} request The set credentials request.
 * @return {object} An object with an errorCode.
 */
function setCredentials(request) {
  var creds = request.userToken;
  var username = creds.username;
  var token = creds.token;

  // Optional
  // Check if the provided username and token are valid through a
  // call to your service. You would have to have a `checkForValidCreds`
  // function defined for this to work.
  var validCreds = checkForValidCreds(username, token);
  if (!validCreds) {
    return {
      errorCode: 'INVALID_CREDENTIALS'
    };
  }
  var userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty('dscc.username', username);
  userProperties.setProperty('dscc.token', token);
  return {
    errorCode: 'NONE'
  };
}

চাবি

data-studio/auth.gs
/**
 * Sets the credentials.
 * @param {Request} request The set credentials request.
 * @return {object} An object with an errorCode.
 */
function setCredentials(request) {
  var key = request.key;

  // Optional
  // Check if the provided key is valid through a call to your service.
  // You would have to have a `checkForValidKey` function defined for
  // this to work.
  var validKey = checkForValidKey(key);
  if (!validKey) {
    return {
      errorCode: 'INVALID_CREDENTIALS'
    };
  }
  var userProperties = PropertiesService.getUserProperties();
  userProperties.setProperty('dscc.key', key);
  return {
    errorCode: 'NONE'
  };
}