Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save houstonhaynes/cfe48982be1d15556be9faa36186e295 to your computer and use it in GitHub Desktop.
Save houstonhaynes/cfe48982be1d15556be9faa36186e295 to your computer and use it in GitHub Desktop.
Example of retrieving a secret from an F# Azure Function App
namespace AzurefnSecret
open Microsoft.Azure.KeyVault
open Microsoft.IdentityModel.Clients.ActiveDirectory
module Example =
let getSecret (appKeyDescription:string) (appKeyValue:string) (secretUrl:string) =
async {
use keyVault = new KeyVaultClient(fun authority resource (_:string) ->
async {
let authContext = AuthenticationContext(authority)
let credential = ClientCredential (appKeyDescription, appKeyValue)
let! token = authContext.AcquireTokenAsync (resource, credential) |> Async.AwaitTask
return token.AccessToken
} |> Async.StartAsTask)
let! secret = keyVault.GetSecretAsync (secretUrl) |> Async.AwaitTask
return secret.Value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment