对于任何关注的人,我都想出了答案,或者至少是一种使用客户端凭据的方法。简而言之,首先您需要获得一个 oauth2 令牌。然后,您需要在以后的所有请求中设置该令牌。您将需要一个客户端 ID、客户端密钥和租户 ID。
这是一个使用 rest-client 和 json 的示例:
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