Class: SimpleOAuth::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_oauth/parser.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Parses OAuth Authorization headers

Constant Summary collapse

PARAM_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Pattern to match OAuth key-value pairs: key="value"

/(\w+)="([^"]*)"\s*(,?)\s*/
OAUTH_PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

OAuth scheme prefix

/OAuth\s+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(header) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new Parser for the given header string

Parameters:

  • header (String, #to_s)

    the OAuth Authorization header string



29
30
31
32
# File 'lib/simple_oauth/parser.rb', line 29

def initialize(header)
  @scanner = StringScanner.new(header.to_s)
  @attributes = {}
end

Instance Attribute Details

#attributesHash{Symbol => String} (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The parsed OAuth attributes

Returns:

  • (Hash{Symbol => String})

    the parsed attributes



23
24
25
# File 'lib/simple_oauth/parser.rb', line 23

def attributes
  @attributes
end

#scannerStringScanner (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The StringScanner instance for parsing the header

Returns:

  • (StringScanner)

    the scanner



18
19
20
# File 'lib/simple_oauth/parser.rb', line 18

def scanner
  @scanner
end

Instance Method Details

#parse(valid_keys) ⇒ Hash{Symbol => String}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses the OAuth Authorization header

Parameters:

  • valid_keys (Array<Symbol>)

    the valid OAuth parameter keys

Returns:

  • (Hash{Symbol => String})

    the parsed attributes

Raises:



39
40
41
42
43
44
# File 'lib/simple_oauth/parser.rb', line 39

def parse(valid_keys)
  scan_oauth_prefix
  scan_params(valid_keys)
  verify_complete
  attributes
end