Class: Azure::Auth::TokenProvider::MsiTokenSource
- Inherits:
-
Object
- Object
- Azure::Auth::TokenProvider::MsiTokenSource
- Defined in:
- lib/azure/auth/token_provider/msi_token_source.rb
Overview
Provdes OAuth 2.0 access token by calling Azure MV IDMS
Constant Summary collapse
- AZURE_VM_IDMS_ENDPOINT =
'http://169.254.169.254/metadata/identity/oauth2/token'
- API_VERSION =
'api-version=2018-02-01'
Instance Method Summary collapse
Instance Method Details
#token(resource = DEFAULT_RESOURCE) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/azure/auth/token_provider/msi_token_source.rb', line 41 def token(resource = DEFAULT_RESOURCE) query_params = "#{API_VERSION}&resource=#{resource}" uri_src = "#{AZURE_VM_IDMS_ENDPOINT}?#{query_params}" uri = URI.parse(uri_src) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) request['Metadata'] = 'true' response = http.request(request) return nil if response.code != '200' parse_json_token(response.body) end |