#DefaultAzureCredential
Explore tagged Tumblr posts
Text
NodeJS, Azure MySQL, Managed Identity
I couldn’t find any good information on how to connect to Azure Database for MySQL using DefaultAzureCredential, which is a nice way of supporting Azure CLI auth and Managed Identity. I spent some time figuring it out!
Use the mysql2 library - this did not work with mysql
const { DefaultAzureCredential } = require("@azure/identity"); const mysql = require('mysql2'); const credential = new DefaultAzureCredential(); const token = await credential.getToken("https://ossrdbms-aad.database.windows.net") const username = "yourdatabaseusername@youraaddomain@DATABASENAME" var connection = mysql.createConnection({ host: "DATABASENAME.mysql.database.azure.com", user: mysqlUsername, password: token.token, database: "databasename", ssl: { rejectUnauthorized: true }, insecureAuth: true, authPlugins: { mysql_clear_password: () => () => { return Buffer.from(token.token + '\0') } } }); connection.connect();
Instead of supplying your database username, if you're using az cli authentication (e.g. for local development) you could extract your AAD username from token.token, since it's a JWT token. This would probably be a nice convenience.
Unfortunately this doesn't work for managed identity, since the token doesn't contain a username. So! This could be made a bit smarter - either you pass in a database username for a managed identity, fall back to trying to extract it from the token for local development, or else throw an error.
0 notes
Text
#CASBAN6: How to configure Azurite to use DefaultAzureCredential with Docker on macOS
I just blogged: #CASBAN6: How to configure Azurite to use DefaultAzureCredential with Docker on macOS #Azurite #Azure #AzureStorage #Docker #macOS #AzureSDK
Before we will have a look at the promised facade for uploading files to Azure’s Blob storage, I want to show you how to configure Azurite to use the Microsoft Identity framework with Docker on macOS for local debugging. Using the Identity framework, our local debug environment and the productive rolled out functions will behave the same. If you have been following along, you should already have…
View On WordPress
#Azure#AzureDev#Azurite#Blob#Blob Storage#container#credentials#debugging#DefaultAzureCredential#Docker#local#macOS#setup#storage
0 notes