.net - Casting PSMethod object to Func`2 in Powershell? -
i'm trying make oauth 2.0 service account google drive example https://developers.google.com/drive/service-accounts work in powershell 2.0.
$a= add-type -path "d:\google\oauth\system.web.mvc.dll" -passthru $b= add-type -path "d:\google\oauth\dotnetopenauth.dll" -passthru $c= add-type -path "d:\google\oauth\google.apis.authentication.oauth2.dll" -passthru $d= add-type -path "d:\google\oauth\newtonsoft.json.net35.dll" -passthru $e= add-type -path "d:\google\oauth\google.apis.dll" -passthru $service_account_email = "<my service account email>" $service_account_pkcs12_file_path = "<path certl>" $certificate = new-object system.security.cryptography.x509certificates.x509certificate2($service_account_pkcs12_file_path, "notasecret", [system.security.cryptography.x509certificates.x509keystorageflags]::exportable); $desc= [google.apis.authentication.oauth2.googleauthenticationserver]::description $provider = new-object google.apis.authentication.oauth2.dotnetopenauth.assertionflowclient($desc, $certificate) $provider.serviceaccountid = $service_account_email; $provider.scope = "https://www.google.com/m8/feeds" $func= [google.apis.authentication.oauth2.dotnetopenauth.nativeapplicationclient]::authorizerequest $auth = new-object "google.apis.authentication.oauth2.oauth2authenticator``1[google.apis.authentication.oauth2.dotnetopenauth.assertionflowclient]"($provider, $func);
unfortunately, last new-object results in following error message:
new-object : cannot convert argument "1", value: "static system.void authorizerequest(system.net.httpwebrequest re quest, string accesstoken)", "oauth2authenticator`1" type "system.func`2[google.apis.authentication.oauth2.dotne topenauth.assertionflowclient,dotnetopenauth.oauth2.iauthorizationstate]": "cannot convert "static system.void auth orizerequest(system.net.httpwebrequest request, string accesstoken)" value of type "system.management.automation.psmeth od" type "system.func`2[google.apis.authentication.oauth2.dotnetopenauth.assertionflowclient,dotnetopenauth.oauth2.i authorizationstate]"." @ line:1 char:19 + $auth = new-object <<<< "google.apis.authentication.oauth2.oauth2authenticator``1[google.apis.authentication.oauth2. dotnetopenauth.assertionflowclient]"($provider, $func); + categoryinfo : invalidoperation: (:) [new-object], methodexception + fullyqualifiederrorid : constructorinvokedthrowexception,microsoft.powershell.commands.newobjectcommand
it seems choking when trying deal passing function in.
does know how sort of wizardry generics this?
it complaining type of $func not match expected type of:
system.func`2[google.apis.authentication.oauth2.dotnetopenauth.assertionflowclient,dotnetopenauth.oauth2.iauthorizationstate]
or in c# speak:
func<assertionflowclient, iauthorizationstate>
that is, function must take assertionflowclient , return object implements iauthorizationstate. sure how creating $func? don't see static authorizerequest on docs page.
Comments
Post a Comment