Question

I need to translate line 4 in the code snippet below into VB. For some reason I cannot get this done tonight. I am either too tired or having a brain drain... Can you help?

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
provider.ClientIdentifier = ClientCredentials.ClientID;
provider.ClientSecret = ClientCredentials.ClientSecret;
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication);

Translation tools have gotten me this far, but it's not right.

Dim provider As NativeApplicationClient = New NativeApplicationClient(GoogleAuthenticationServer.Description)
provider.ClientIdentifier = ClientCredentials.ClientID
provider.ClientSecret = ClientCredentials.ClientSecret
Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthorization)

The GetAuthorization method has the following signature.

Private Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState
Was it helpful?

Solution

You need AddressOf

Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)

OTHER TIPS

Refer to this Website for the Translation of any code from C# to VB and the code after conversion is

Dim provider = New NativeApplicationClient(GoogleAuthenticationServer.Description)
provider.ClientIdentifier = ClientCredentials.ClientID
provider.ClientSecret = ClientCredentials.ClientSecret
Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthentication)

You are trying to use OAuth2Authenticator to GetAuthorization and the two are different, maybe that's your problem.

AddressOf never calls the function, you need to use

Dim getAuth As Func(Of NativeApplicationClient, IAuthorizationState) = AddressOf GetAuthorization
Dim auth As New OAuth2Authenticator(Of NativeApplicationClient)(provider, getAuth)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top