0

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

4 Answers 4

3

You need AddressOf

Dim auth As OAuth2Authenticator(Of NativeApplicationClient) = New OAuth2Authenticator(Of NativeApplicationClient)(provider, AddressOf GetAuthorization)
Sign up to request clarification or add additional context in comments.

1 Comment

I knew I was missing something simple. :D Thanks!
1

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)

1 Comment

The DownVoters should say a Reason why?
0

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

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.