c# - Creating a ServiceAccountCredential for a user from a Systems account -


i use following code act on behalf of user through system-login (domain-wide authenticated). example found accomplishes uses reflection set user. know isn't proper way accomplish wondering if me out example of how should solved

serviceaccountcredential credential =      googlecredential.fromjson(google_system_user_auth_information)         .createscoped(scopes)         .underlyingcredential serviceaccountcredential;  var userfield = typeof(serviceaccountcredential).getfield("user",  bindingflags.nonpublic | bindingflags.instance); userfield?.setvalue(credential, google_calendar_username); //act in guise of normal user google_calendar_username   service = new calendarservice(new baseclientservice.initializer() {     httpclientinitializer = credential,     applicationname = applicationname,  }); 

here's how i'd it, setting both scopes , new user @ same time via serviceaccountcredential.initializer:

serviceaccountcredential original = (serviceaccountcredential)     googlecredential.fromjson(google_system_user_auth_information).underlyingcredential;  var initializer = new serviceaccountcredential.initializer(original.id) {     user = google_calendar_username,     key = original.key,     scopes = scopes }; var credentialforuser = new serviceaccountcredential(initializer); 

now gives serviceaccountcredential rather googlecredential. that's current code uses, should okay - nice if there simple way of getting googlecredential too. should make simpler - i've filed issue that.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -