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 gösterilmiştir.
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ı için 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, üçüncü taraf hizmetinde kullanıcı için depolanan kimlik bilgilerini siler.
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 hizmeti için kimlik doğrulamanın geçerli olup olmadığını belirlemek amacıyla çağrılır. Kimlik doğrulama geçerliyse getData()
ve getSchema()
çağrılarının yetkisiz erişim nedeniyle başarısız olmaması beklenir. Yetkilendirme geçerli değilse kullanıcı, yetkilendirme akışını başlatmak için 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'yi ekleme ve kurma
Apps Komut Dosyası için OAuth2 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 herhangi bir işlev adı olabilir. Ancak kodunuzda OAuth2 hizmetine başvuruda bulunurken 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.
Apps Komut Dosyası için OAuth2 kitaplığını kullanarak OAuth 2.0 geri çağırma işleminin nasıl yapılacağını gösteren örnek:
get3PAuthorizationUrls()
Bu işlev, üçüncü taraf hizmetin kimlik doğrulama akışını başlatmak için gereken URL'yi almak amacıyla ç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 bir düğme veya bağlantı olarak gösterilir. get3PAuthorizationUrls() referansına bakın.
Apps Komut Dosyası için OAuth2 kitaplığını kullanarak yetkilendirme URL'si döndürme örneği:
USER_PASS
, USER_TOKEN
, KEY
, PATH_USER_PASS
ve PATH_KEY
Aşağıdakiler 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ı topluluk bağlayıcısı yapılandırma sayfasına kimlik bilgisi bilgilerini girdikten sonra çağrılır. Kimlik bilgilerini UserProperties
ile kullanıcı bazında kaydetmek için Mülk Hizmeti'ni 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'
};
}