Created
January 5, 2018 20:58
-
-
Save ninjarobot/a1fba42b37abe64fe70362747a01e80c to your computer and use it in GitHub Desktop.
Example of retrieving a secret from an F# Azure Function App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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