lib/cerner/oauth1a/access_token.rb
def authorization_header(
        nonce: nil, timestamp: nil, http_method: 'GET', fully_qualified_url: nil, request_params: nil
      )
        oauth_params = {}
        oauth_params[:oauth_version] = '1.0'
        oauth_params[:oauth_signature_method] = @signature_method
        oauth_params[:oauth_consumer_key] = @consumer_key
        oauth_params[:oauth_nonce] = nonce if nonce
        oauth_params[:oauth_timestamp] = Internal.convert_to_time(time: timestamp, name: 'timestamp').to_i if timestamp
        oauth_params[:oauth_token] = @token

        if @signature
          sig = @signature
        else
          # NOTE: @accessor_secret is always used, but an empty value is allowed and project assumes
          # that nil implies an empty value

          raise OAuthError.new('token_secret is nil', nil, 'parameter_absent', nil, @realm) unless @token_secret

          if @signature_method == 'PLAINTEXT'
            sig =
              Signature.sign_via_plaintext(client_shared_secret: @accessor_secret, token_shared_secret: @token_secret)
          elsif @signature_method == 'HMAC-SHA1'
            http_method ||= 'GET' # default to HTTP GET
            request_params ||= {} # default to no request params
            oauth_params[:oauth_nonce] = Internal.generate_nonce unless oauth_params[:oauth_nonce]
            oauth_params[:oauth_timestamp] = Internal.generate_timestamp unless oauth_params[:oauth_timestamp]

            begin
              fully_qualified_url = Internal.convert_to_http_uri(url: fully_qualified_url, name: 'fully_qualified_url')
            rescue ArgumentError => ae
              raise OAuthError.new(ae.message, nil, 'parameter_absent', nil, @realm)
            end

            query_params = fully_qualified_url.query ? Protocol.parse_url_query_string(fully_qualified_url.query) : {}
            request_params = query_params.merge(request_params)

            params = request_params.merge(oauth_params)
            signature_base_string =
              Signature.build_signature_base_string(
                http_method: http_method, fully_qualified_url: fully_qualified_url, params: params
              )

            sig =
              Signature.sign_via_hmacsha1(
                client_shared_secret: @accessor_secret,
                token_shared_secret: @token_secret,
                signature_base_string: signature_base_string
              )
          else
            raise OAuthError.new('signature_method is invalid', nil, 'signature_method_rejected', nil, @realm)
          end
        end

        oauth_params[:realm] = @realm if @realm
        oauth_params[:oauth_signature] = sig

        Protocol.generate_authorization_header(oauth_params)
      end
# Public: Generates a value suitable for use as an HTTP Authorization header. If #signature is
# nil, then a signature will be generated based on the #signature_method.
#
# PLAINTEXT Signature (preferred)
#
# When using PLAINTEXT signatures, no additional arguments are necessary. If an oauth_nonce
# or oauth_timestamp are desired, then the values can be passed via the :nonce and :timestamp
# keyword arguments. The actual signature will be constructed from the Accessor Secret
# (#accessor_secret) and the Token Secret (#token_secret).
#
# HMAC-SHA1 Signature
#
# When using HMAC-SHA1 signatures, access to the HTTP request information is necessary. This
# requies that additional information is passed via the keyword arguments. The required
# information includes the HTTP method (see :http_method), the host authority & path (see
# :fully_qualified_url) and the request parameters (see :fully_qualified_url and
# :request_params).
#
# keywords - The keyword arguments:
#            :nonce               - The optional String containing a Nonce to generate the
#                                   header with HMAC-SHA1 signatures. When nil, a Nonce will
#                                   be generated.
#            :timestamp           - The optional Time or #to_i compliant object containing a
#                                   Timestamp to generate the header with HMAC-SHA1
#                                   signatures. When nil, a Timestamp will be generated.
#            :http_method         - The optional String or Symbol containing a HTTP Method for
#                                   constructing the HMAC-SHA1 signature. When nil, the value
#                                   defualts to 'GET'.
#            :fully_qualified_url - The optional String or URI containing the fully qualified
#                                   URL of the HTTP API being invoked for constructing the
#                                   HMAC-SHA1 signature. If the URL contains a query string,
#                                   the parameters will be extracted and used in addition to
#                                   the :request_params keyword argument.
#            :request_params      - The optional Hash of name/value pairs containing the
#                                   request parameters of the HTTP API being invoked for
#                                   constructing the HMAC-SHA1 signature. Parameters passed
#                                   here will override and augment those passed in the
#                                   :fully_qualified_url parameter. The parameter names and
#                                   values MUST be unencoded. See
#                                   Protocol#parse_url_query_string for help with decoding an
#                                   encoded query string.
#
# Returns a String representation of the access token.
#
# Raises Cerner::OAuth1a::OAuthError if #signature_method is not PLAINTEXT or if a signature
# can't be determined.
Generates a value suitable for use as an HTTP Authorization header. If #signature is
nil, then a signature will be generated based on the #signature_method.

PLAINTEXT Signature (preferred)

When using PLAINTEXT signatures, no additional arguments are necessary. If an oauth_nonce
or oauth_timestamp are desired, then the values can be passed via the :nonce and :timestamp
keyword arguments. The actual signature will be constructed from the Accessor Secret
(#accessor_secret) and the Token Secret (#token_secret).

HMAC-SHA1 Signature

When using HMAC-SHA1 signatures, access to the HTTP request information is necessary. This
requies that additional information is passed via the keyword arguments. The required
information includes the HTTP method , the host authority & path (see
:fully_qualified_url) and the request parameters (see :fully_qualified_url and
:request_params).

The keyword arguments:
:nonce               - The optional String containing a Nonce to generate the
header with HMAC-SHA1 signatures. When nil, a Nonce will
be generated.
:timestamp           - The optional Time or #to_i compliant object containing a
Timestamp to generate the header with HMAC-SHA1
signatures. When nil, a Timestamp will be generated.
:http_method         - The optional String or Symbol containing a HTTP Method for
constructing the HMAC-SHA1 signature. When nil, the value
defualts to 'GET'.
:fully_qualified_url - The optional String or URI containing the fully qualified
URL of the HTTP API being invoked for constructing the
HMAC-SHA1 signature. If the URL contains a query string,
the parameters will be extracted and used in addition to
the :request_params keyword argument.
:request_params      - The optional Hash of name/value pairs containing the
request parameters of the HTTP API being invoked for
constructing the HMAC-SHA1 signature. Parameters passed
here will override and augment those passed in the
:fully_qualified_url parameter. The parameter names and
values MUST be unencoded. See
Protocol#parse_url_query_string for help with decoding an
encoded query string.

Returns a String representation of the access token.

Raises Cerner::OAuth1a::OAuthError if #signature_method is not PLAINTEXT or if a signature
can't be determined.
Generates a value suitable for use as an HTTP Authorization header . If #signature is nil then a signature will be generated based on the #signature_method . PLAINTEXT Signature ( preferred ) When using PLAINTEXT signatures no additional arguments are necessary . If an oauth_nonce or oauth_timestamp are desired then the values can be passed via the : nonce and : timestamp keyword arguments . The actual signature will be constructed from the Accessor Secret ( #accessor_secret ) and the Token Secret ( #token_secret ) . HMAC - SHA1 Signature When using HMAC - SHA1 signatures access to the HTTP request information is necessary . This requies that additional information is passed via the keyword arguments . The required information includes the HTTP method the host authority & path ( see : fully_qualified_url ) and the request parameters ( see : fully_qualified_url and : request_params ) . The keyword arguments : : nonce - The optional String containing a Nonce to generate the header with HMAC - SHA1 signatures . When nil a Nonce will be generated . : timestamp - The optional Time or #to_i compliant object containing a Timestamp to generate the header with HMAC - SHA1 signatures . When nil a Timestamp will be generated . : http_method - The optional String or Symbol containing a HTTP Method for constructing the HMAC - SHA1 signature . When nil the value defualts to ' GET ' . : fully_qualified_url - The optional String or URI containing the fully qualified URL of the HTTP API being invoked for constructing the HMAC - SHA1 signature . If the URL contains a query string the parameters will be extracted and used in addition to the : request_params keyword argument . : request_params - The optional Hash of name / value pairs containing the request parameters of the HTTP API being invoked for constructing the HMAC - SHA1 signature . Parameters passed here will override and augment those passed in the : fully_qualified_url parameter . The parameter names and values MUST be unencoded . See Protocol#parse_url_query_string for help with decoding an encoded query string . Returns a String representation of the access token . Raises Cerner :: OAuth1a :: OAuthError if #signature_method is not PLAINTEXT or if a signature can ' t be determined .
def authorization_header(
        nonce: nil, timestamp: nil, http_method: 'GET', fully_qualified_url: nil, request_params: nil
      )
        oauth_params = {}
        oauth_params[:oauth_version] = '1.0'
        oauth_params[:oauth_signature_method] = @signature_method
        oauth_params[:oauth_consumer_key] = @consumer_key
        oauth_params[:oauth_nonce] = nonce if nonce
        oauth_params[:oauth_timestamp] = Internal.convert_to_time(time: timestamp, name: 'timestamp').to_i if timestamp
        oauth_params[:oauth_token] = @token
        if @signature
          sig = @signature
        else
          raise OAuthError.new('token_secret is nil', nil, 'parameter_absent', nil, @realm) unless @token_secret
          if @signature_method == 'PLAINTEXT'
            sig =
              Signature.sign_via_plaintext(client_shared_secret: @accessor_secret, token_shared_secret: @token_secret)
          elsif @signature_method == 'HMAC-SHA1'
            http_method ||= 'GET' 
            request_params ||= {} 
            oauth_params[:oauth_nonce] = Internal.generate_nonce unless oauth_params[:oauth_nonce]
            oauth_params[:oauth_timestamp] = Internal.generate_timestamp unless oauth_params[:oauth_timestamp]
            begin
              fully_qualified_url = Internal.convert_to_http_uri(url: fully_qualified_url, name: 'fully_qualified_url')
            rescue ArgumentError => ae
              raise OAuthError.new(ae.message, nil, 'parameter_absent', nil, @realm)
            end
            query_params = fully_qualified_url.query ? Protocol.parse_url_query_string(fully_qualified_url.query) : {}
            request_params = query_params.merge(request_params)
            params = request_params.merge(oauth_params)
            signature_base_string =
              Signature.build_signature_base_string(
                http_method: http_method, fully_qualified_url: fully_qualified_url, params: params
              )
            sig =
              Signature.sign_via_hmacsha1(
                client_shared_secret: @accessor_secret,
                token_shared_secret: @token_secret,
                signature_base_string: signature_base_string
              )
          else
            raise OAuthError.new('signature_method is invalid', nil, 'signature_method_rejected', nil, @realm)
          end
        end
        oauth_params[:realm] = @realm if @realm
        oauth_params[:oauth_signature] = sig
        Protocol.generate_authorization_header(oauth_params)
      end
def authorization_header ( nonce : nil , timestamp : nil , http_method : 'GET' , fully_qualified_url : nil , request_params : nil ) oauth_params = { } oauth_params [ :oauth_version ] = '1.0' oauth_params [ :oauth_signature_method ] = @signature_method oauth_params [ :oauth_consumer_key ] = @consumer_key oauth_params [ :oauth_nonce ] = nonce if nonce oauth_params [ :oauth_timestamp ] = Internal . convert_to_time ( time : timestamp , name : 'timestamp' ) . to_i if timestamp oauth_params [ :oauth_token ] = @token if @signature sig = @signature else raise OAuthError . new ( 'token_secret is nil' , nil , 'parameter_absent' , nil , @realm ) unless @token_secret if @signature_method == 'PLAINTEXT' sig = Signature . sign_via_plaintext ( client_shared_secret : @accessor_secret , token_shared_secret : @token_secret ) elsif @signature_method == 'HMAC-SHA1' http_method ||= 'GET' request_params ||= { } oauth_params [ :oauth_nonce ] = Internal . generate_nonce unless oauth_params [ :oauth_nonce ] oauth_params [ :oauth_timestamp ] = Internal . generate_timestamp unless oauth_params [ :oauth_timestamp ] begin fully_qualified_url = Internal . convert_to_http_uri ( url : fully_qualified_url , name : 'fully_qualified_url' ) rescue ArgumentError => ae raise OAuthError . new ( ae . message , nil , 'parameter_absent' , nil , @realm ) end query_params = fully_qualified_url . query ? Protocol . parse_url_query_string ( fully_qualified_url . query ) : { } request_params = query_params . merge ( request_params ) params = request_params . merge ( oauth_params ) signature_base_string = Signature . build_signature_base_string ( http_method : http_method , fully_qualified_url : fully_qualified_url , params : params ) sig = Signature . sign_via_hmacsha1 ( client_shared_secret : @accessor_secret , token_shared_secret : @token_secret , signature_base_string : signature_base_string ) else raise OAuthError . new ( 'signature_method is invalid' , nil , 'signature_method_rejected' , nil , @realm ) end end oauth_params [ :realm ] = @realm if @realm oauth_params [ :oauth_signature ] = sig Protocol . generate_authorization_header ( oauth_params ) end
Public: Generates a value suitable for use as an HTTP Authorization header.
Public : Generates a value suitable for use as an HTTP Authorization header .
# NOTE: @accessor_secret is always used, but an empty value is allowed and project assumes # that nil implies an empty value # default to HTTP GET # default to no request params
nonce
timestamp
http_method
fully_qualified_url
request_params