The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Azure and client connections

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Daniel Berger

Posts: 1383
Nickname: djberg96
Registered: Sep, 2004

Daniel Berger is a Ruby Programmer who also dabbles in C and Perl
Azure and client connections Posted: Jun 18, 2015 9:18 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Daniel Berger.
Original Post: Azure and client connections
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Daniel Berger
Latest Posts From Testing 1,2,3...

Advertisement
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.

require 'rest-client'
require 'json'

token_url = "https://login.windows.net/" + tenant_id + "/oauth2/token"

resp = RestClient.post(
  token_url,
  :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(
"https://management.azure.com/providers?api-version=2015-01=01",
:content_type => 'application/json',
:authorization => token
)

p resp.body

Read: Azure and client connections

Topic: Drop Books Previous Topic   Next Topic Topic: All We Need To Do Is...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use