0
votes

I am trying to convert the example code at https://docs.microsoft.com/en-us/azure/key-vault/tutorial-net-create-vault-azure-web-app to VB.net and use it to access a secret that I have stored in my Azure Key Vault. I used the converter at http://converter.telerik.com/.

The converted code gives an error saying "Delegate 'KeyVaultClient.AuthenticationCallback' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor."

This is the converted code:

Imports Microsoft.Azure.KeyVault
Imports Microsoft.Azure.Services.AppAuthentication
Imports Microsoft.Azure.KeyVault.Models

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim azureServiceTokenProvider As AzureServiceTokenProvider = New AzureServiceTokenProvider

        Dim keyVaultClient As KeyVaultClient = New KeyVaultClient(New KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback))
        Dim secret As String = keyVaultClient.GetSecretAsync("https://<YourKeyVaultName>.vault.azure.net/secrets/AppSecret").ConfigureAwait(False)
        TextBox1.Text = secret.Value

    End Sub

I would like to know the code necessary to access a secret in my key vault. I have given my app all permissions to access the vault in the Azure portal and I am logged in with my Azure account in VS2017 and I have been at this for 3 days and cannot find any VB examples for accessing key vault that are current.

1
Firstly, the only code converter you should use is Instant VB from Tangible Software Solutions. The free version is all most people need when converting short snippets.jmcilhinney
As for the issue, the error message really gives you all the information you need, if you have taken the time to learn VB to the necessary degree. The error message tells you exactly where the issue is (the KeyVaultClient.AuthenticationCallback constructor) and it provides keywords including "delegate", AddressOf and "lambda expression". What efforts have you made to learn about those?jmcilhinney
I can see from this post stackoverflow.com/questions/57169283/setting-up-azure-key-vault that you've found an answer for your question, would you like to share your answer with others please ?Thomas
While it would appear that I have found an answer, the answer is as yet incomplete. While on another forum I did find what is probably the correct translation to the code above. However, I have not yet been able to retrieve my secret and therefore I do not yet conclude that I have the correct answer. There could still be tweaks necessary in the code that you see at stackoverflow.com/questions/57169283/setting-up-azure-key-vault in order to get this to work. However, I do suspect that the problem now lies in the setting on Azure rather than in the code in my app.Jamie

1 Answers

0
votes

You can refer read-azure-secrets which is for node.js