|Azure and client connections
||[Jun. 18th, 2015|08:52 am]
For anyone out there wondering how to do client side connections with Ruby and Azure, this should get you going. It took me a while to figure this out because the vast majority of the examples online assume you're doing this strictly within a web app and send the token to a reply-url, which is obviously unsuitable for scripting. So, here you go.
token_url = "https://login.windows.net/" + tenant_id + "/oauth2/token"
resp = RestClient.post(
:grant_type => 'client_credentials',
:client_id => 'xxxxx',
:client_secret => 'yyyyy',
:resource => 'https://management.azure.com'
token = 'Bearer ' + JSON.parse(resp)['access_token']
# Now attach that token to all future requests:
resp = RestClient.get(
:content_type => 'application/json',
:authorization => token