Topluluk bağlayıcıları aşağıdaki kimlik doğrulama yöntemlerini destekler:
- OAuth 2.0
- Yol/Kullanıcı adı/Şifre
- Yol/Anahtar
- Kullanıcı adı/şifre
- Kullanıcı adı/Jeton
- Anahtar
- Yok
Kullandığınız yönteme bağlı olarak bağlayıcınızda ek işlevler sağlamanız gerekir.
Aşağıdaki tabloda, bağlayıcınızın kimlik doğrulama türüne bağlı olarak hangi işlevleri tanımlamanız gerektiği belirtilmektedir.
OAUTH2 | PATH_USER_PASS PATH_KEY USER_PASS USER_TOKEN KEY |
YOK | |
---|---|---|---|
getAuthType() |
zorunlu | zorunlu | zorunlu |
resetAuth() |
zorunlu | zorunlu | |
isAuthValid() |
zorunlu | zorunlu | |
authCallback() |
zorunlu | ||
get3PAuthorizationUrls() |
zorunlu | ||
setCredentials() |
zorunlu |
getAuthType()
Bu işlev, bağlayıcının kimlik doğrulama türünü döndürmelidir.
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
YOK
resetAuth()
Bu işlev, kullanıcı için üçüncü taraf hizmetinde depolanan tüm kimlik bilgilerini temizler.
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()
Bu işlev, üçüncü taraf hizmetinin kimlik doğrulamasının geçerli olup olmadığını belirlemek için çağrılır. Kimlik doğrulama geçerliyse getData()
ve getSchema()
çağrıları yetkisiz erişim nedeniyle başarısız olmaz. Kimlik doğrulama geçerli değilse kullanıcı, yetkilendirme akışını başlatması için bir bildirim alabilir.
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
Apps Komut Dosyası kitaplığı için OAuth2 ekleme ve ayarlama
OAuth2 for Apps Script kitaplığını bağlayıcı projenize eklemek için kurulum talimatlarını uygulayın. Ardından, bağlayıcı projenizde bir OAuth2 hizmeti oluşturmak için kullanım kılavuzundaki ilk adımı uygulayın. OAuth2 hizmetinizin geçerli bir işlev adı olabilir ancak kodunuzda OAuth2 hizmetine referans verirken aynı adı kullandığınızdan emin olun.
Örneğin, exampleService
adlı bir OAuth2 hizmeti:
authCallback()
Bu işlev, OAuth 2.0 akışını tamamlamak için çağrılır. Üçüncü taraf kimlik doğrulama hizmetinden gelen geri çağırma yanıtı, bağımsız değişken olarak sağlanır ve bu işlev tarafından işlenmelidir.
OAuth2 for Apps Script kitaplığını kullanarak OAuth 2.0 geri çağırmasını işleme örneği:
get3PAuthorizationUrls()
Bu işlev, üçüncü taraf hizmeti için kimlik doğrulama akışını başlatmak üzere gereken URL'yi almak için çağrılır. isAuthValid
false
değerini döndürürse döndürülen URL, kullanıcıya üçüncü taraf hizmetine erişimi yetkilendirebilmesi için düğme veya bağlantı olarak gösterilir. get3PAuthorizationUrls() referansına bakın.
Apps Script için OAuth2 kitaplığını kullanarak yetkilendirme URL'sini döndürme örneği:
USER_PASS
, USER_TOKEN
, KEY
, PATH_USER_PASS
ve PATH_KEY
Aşağıdaki bilgiler yalnızca USER_PASS
, USER_TOKEN
, KEY
, PATH_USER_PASS
ve PATH_KEY
kimlik doğrulama akışları için gereklidir.
setCredentials()
setCredentials
, kullanıcı kimlik bilgilerini topluluk bağlayıcısı yapılandırma sayfasına girdikten sonra çağrılır. Kimlik bilgilerini kullanıcı bazında kaydetmek için UserProperties
kullanarak Properties Service'i kullanmanız gerekir.
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'
};
}