class Azure::Auth::TokenProvider

Token provider gives an access to OAuth2.0 token

Constants

DEFAULT_RESOURCE
VERSION

Public Instance Methods

token(resource = DEFAULT_RESOURCE) click to toggle source

Returns an access token @param resource [String] Azure resource URI @return [AzureMSITokenProvider::Token]

# File lib/azure/auth/token_provider.rb, line 40
def token(resource = DEFAULT_RESOURCE)
  @token = read_token_from_source(resource) if
    @token.nil? ||
    @token.is_expired? ||
    @token.resource != resource
end

Private Instance Methods

read_token_from_source(resource) click to toggle source

Reads an access token from one of the known token sources @return [AzureMSITokenProvider::Token]

# File lib/azure/auth/token_provider.rb, line 51
def read_token_from_source(resource)
  return @selected_source.token unless @selected_source.nil?

  token_sources.each do |ts|
    begin
      t = ts.token(resource)
      @selected_source = ts
      return t
    rescue StandardError
      next
    end
  end
end
token_sources() click to toggle source

Returns an array of token sources @return [Array<#token>]

# File lib/azure/auth/token_provider.rb, line 67
def token_sources
  [AzureCliTokenSource.new, MsiTokenSource.new]
end