문제

I'm successfully using service accounts for domain-wide authority to access users' drive files and calendars as follows:

ServiceAccountCredential.Initializer initializer =
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = serviceAccountScope,
        User = "user1@myDomain.com"
    }.FromCertificate(certificate);

ServiceAccountCredential credential = new ServiceAccountCredential(initializer);

service = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = appName,
});

However, I'm not entirely sure the best way to change users, especially if I'm dealing with many users at once. Is it best to just start over and create a new initializer and service for each user? Or is it possible to keep the same service and just update the imitated user?

도움이 되었습니까?

해결책

The way ServiceAccountCredential was designed is that it's thread safe, so you can't change the User data. However, we may change the current getter property User to be similar Token (in the way that we look when getting and setting it). Please feel free to open a new issue in our issue tracker and elaborate more.

For now, you should use a new service and for each "user", as following:

ServiceAccountCredential.Initializer initializer =
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = serviceAccountScope,
        User = "user1@myDomain.com"
    }.FromCertificate(certificate);

var service1 = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = new ServiceAccountCredential(initializer),
    ApplicationName = appName,
});

initializer.User = "user2@myDomain.com"
var service2 = new DriveService(new BaseClientService.Initializer()
{
    HttpClientInitializer = new ServiceAccountCredential(initializer),`
    ApplicationName = appName,
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top