This file is indexed.

/usr/lib/ruby/vendor_ruby/ms_rest/credentials/token_credentials.rb is in ruby-ms-rest 0.6.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

module MsRest
  #
  # Class which keeps functionality and date for performing OAuth (token based) authentication.
  #
  class TokenCredentials < ServiceClientCredentials

    private

    DEFAULT_SCHEME = 'Bearer'

    # @return [String] the scheme for arranging token in the HTTP header.
    attr_accessor :token_provider

    public

    #
    # Creates and initialize new instance of the TokenCredentials class.
    # @param token_provider [TokenProvider] the token provider.
    # @param token [String] the token.
    def initialize(*args)
      if (args.size == 1)
        if args[0].respond_to? :get_authentication_header
          @token_provider = args[0]
        elsif args[0].is_a? String
          @token_provider = StringTokenProvider.new args[0], DEFAULT_SCHEME
        else
          fail ArgumentError, 'Invalid argument was passed, is can be either TokenProvider or token'
        end
      elsif (args.size == 2)
        token = args[0]
        token_type = args[1]
        @token_provider = StringTokenProvider.new token, token_type
      else
        fail ArgumentError, 'Invalid number of parameters was passed to TokenCredentials constructor, valid number is 1 or 2'
      end
    end

    #
    # Attaches OAuth authentication header to the given HTTP request.
    # @param request [Net::HTTPRequest] the request authentication header needs to be attached to.
    #
    # @return [Net::HTTPRequest] request with attached authentication header
    def sign_request(request)
      super(request)
      header = @token_provider.get_authentication_header

      if (request.respond_to?(:request_headers))
        request.request_headers[AUTHORIZATION] = header
      elsif request.respond_to?(:headers)
        request.headers[AUTHORIZATION] = header
      else
        fail ArgumentError, 'Incorrect request object was provided'
      end
    end

  end
end