simple_oauth 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/mutant.yml ADDED
@@ -0,0 +1,17 @@
1
+ usage: opensource
2
+ integration:
3
+ name: minitest
4
+ includes:
5
+ - lib
6
+ - test
7
+ requires:
8
+ - simple_oauth
9
+ mutation:
10
+ operators: full
11
+ timeout: 5.0
12
+ matcher:
13
+ subjects:
14
+ - SimpleOAuth*
15
+ coverage_criteria:
16
+ process_abort: true
17
+ test_result: true
@@ -0,0 +1,6 @@
1
+ # Extension to MatchData for indexed access with Integer
2
+ class MatchData
3
+ # Override [] to return non-nil String for Integer index
4
+ # (when we know the group exists)
5
+ def []: (Integer index) -> String
6
+ end
@@ -0,0 +1,9 @@
1
+ # Extensions to OpenSSL types
2
+ module OpenSSL
3
+ module PKey
4
+ class PKey
5
+ # Sign with digest name as String (in addition to Digest object)
6
+ def sign: (String | OpenSSL::Digest digest, String data) -> String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module SimpleOAuth
2
+ class Header
3
+ # Class methods for Header - parsing, defaults, and body hashing
4
+ module ClassMethods
5
+ # Returns default OAuth options with generated nonce and timestamp
6
+ def default_options: (?String? body) -> Header::oauth_options
7
+
8
+ # Computes the oauth_body_hash for a request body
9
+ def body_hash: (String? body, ?String algorithm) -> String
10
+
11
+ # Parses an OAuth Authorization header string into a hash
12
+ def parse: (String | _ToS header) -> Header::oauth_options
13
+
14
+ # Parses OAuth parameters from a form-encoded POST body
15
+ def parse_form_body: (String | _ToS body) -> Header::oauth_options
16
+
17
+ private
18
+
19
+ # Generates a random nonce for OAuth requests
20
+ def generate_nonce: () -> String
21
+
22
+ # Encodes binary data as Base64 without newlines
23
+ def encode_base64: (String data) -> String
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ module SimpleOAuth
2
+ # Parses OAuth Authorization headers
3
+ class Parser
4
+ # Pattern to match OAuth key-value pairs
5
+ PARAM_PATTERN: Regexp
6
+
7
+ # OAuth scheme prefix pattern
8
+ OAUTH_PREFIX: Regexp
9
+
10
+ attr_reader scanner: StringScanner
11
+ attr_reader attributes: Hash[Symbol, String]
12
+
13
+ def initialize: (String | _ToS header) -> void
14
+ def parse: (Array[Symbol] valid_keys) -> Hash[Symbol, String]
15
+
16
+ private
17
+
18
+ def scan_oauth_prefix: () -> void
19
+ def scan_params: (Array[Symbol] valid_keys) -> void
20
+ def validate_comma_separator: (String key, String comma) -> void
21
+ def store_if_valid: (String key, String value, Array[Symbol] valid_keys) -> void
22
+ def verify_complete: () -> void
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ # Signature computation methods for OAuth 1.0
2
+ #
3
+ # This module provides a registry of signature methods that can be extended
4
+ # with custom implementations.
5
+ module SimpleOAuth
6
+ module Signature
7
+ # Type for signature implementation block
8
+ type signature_block = ^(String secret, String signature_base) -> String
9
+
10
+ # Type for registry entry
11
+ type registry_entry = { implementation: signature_block, rsa: bool }
12
+
13
+ # Registry of signature method implementations (class-level instance variable)
14
+ self.@registry: Hash[String, registry_entry]
15
+
16
+ # Registers a custom signature method
17
+ def self.register: (String | Symbol name, ?rsa: bool) { (String, String) -> String } -> void
18
+
19
+ # Checks if a signature method is registered
20
+ def self.registered?: (String | Symbol name) -> bool
21
+
22
+ # Returns list of registered signature method names
23
+ def self.methods: () -> Array[String]
24
+
25
+ # Checks if a signature method uses RSA
26
+ def self.rsa?: (String | Symbol name) -> bool
27
+
28
+ # Computes a signature using the specified method
29
+ def self.sign: (String | Symbol name, String? secret, String signature_base) -> String
30
+
31
+ # Unregisters a signature method
32
+ def self.unregister: (String | Symbol name) -> void
33
+
34
+ # Resets the registry to only built-in methods
35
+ def self.reset!: () -> void
36
+
37
+ # Encodes binary data as Base64 without newlines
38
+ def self.encode_base64: (String data) -> String
39
+
40
+ private
41
+
42
+ # Normalizes signature method name for registry lookup
43
+ def self.normalize_name: (String | Symbol name) -> String
44
+
45
+ # Registers the built-in OAuth signature methods
46
+ def self.register_builtin_methods: () -> void
47
+
48
+ # Registers HMAC-based signature methods
49
+ def self.register_hmac_methods: () -> void
50
+
51
+ # Registers RSA-based signature methods
52
+ def self.register_rsa_methods: () -> void
53
+
54
+ # Registers the PLAINTEXT signature method
55
+ def self.register_plaintext_method: () -> void
56
+ end
57
+ end
@@ -0,0 +1,158 @@
1
+ # OAuth 1.0 header generation library
2
+ module SimpleOAuth
3
+ # Error raised when parsing a malformed OAuth Authorization header
4
+ class ParseError < StandardError
5
+ end
6
+
7
+ # Error raised when invalid options are passed to Header
8
+ class InvalidOptionsError < StandardError
9
+ end
10
+
11
+ # OAuth percent-encoding utilities
12
+ module Encoding
13
+ # Characters that don't need to be escaped per OAuth spec
14
+ UNRESERVED_CHARS: Regexp
15
+
16
+ # Percent-encodes a value according to OAuth specification
17
+ def escape: (String | _ToS value) -> String
18
+
19
+ # Alias for escape
20
+ def encode: (String | _ToS value) -> String
21
+
22
+ # Decodes a percent-encoded value
23
+ def unescape: (String | _ToS value) -> String
24
+
25
+ # Alias for unescape
26
+ def decode: (String | _ToS value) -> String
27
+
28
+ # Module-level methods (via extend self)
29
+ def self.escape: (String | _ToS value) -> String
30
+ def self.encode: (String | _ToS value) -> String
31
+ def self.unescape: (String | _ToS value) -> String
32
+ def self.decode: (String | _ToS value) -> String
33
+ end
34
+
35
+ # Generates OAuth 1.0 Authorization headers for HTTP requests
36
+ class Header
37
+ # OAuth header scheme prefix
38
+ OAUTH_SCHEME: String
39
+
40
+ # Prefix for OAuth parameters
41
+ OAUTH_PREFIX: String
42
+
43
+ # Default signature method per RFC 5849
44
+ DEFAULT_SIGNATURE_METHOD: String
45
+
46
+ # OAuth version
47
+ OAUTH_VERSION: String
48
+
49
+ # Valid OAuth attribute keys that can be included in the header
50
+ ATTRIBUTE_KEYS: Array[Symbol]
51
+
52
+ # Keys that are used internally but should not appear in attributes
53
+ IGNORED_KEYS: Array[Symbol]
54
+
55
+ # Valid keys when parsing OAuth parameters (ATTRIBUTE_KEYS + signature)
56
+ PARSE_KEYS: Array[Symbol]
57
+
58
+ # Type aliases for clarity
59
+ type oauth_key = :body_hash | :callback | :consumer_key | :nonce | :signature_method | :timestamp | :token | :verifier | :version
60
+ type ignored_key = :consumer_secret | :token_secret | :signature | :realm | :ignore_extra_keys
61
+ type signature_method = "HMAC-SHA1" | "HMAC-SHA256" | "RSA-SHA1" | "RSA-SHA256" | "PLAINTEXT"
62
+ type params_hash = Hash[String | Symbol, untyped]
63
+ type oauth_options = Hash[Symbol, untyped]
64
+ type signed_attributes_hash = Hash[Symbol, untyped]
65
+
66
+ # The HTTP method for the request
67
+ attr_reader method: String
68
+
69
+ # The request parameters to be signed
70
+ attr_reader params: params_hash
71
+
72
+ # The raw request body for oauth_body_hash computation
73
+ attr_reader body: String?
74
+
75
+ # The OAuth options including credentials and signature
76
+ attr_reader options: oauth_options
77
+
78
+ # Class methods from ClassMethods module
79
+ extend ClassMethods
80
+
81
+ # Encoding methods from Encoding module
82
+ extend Encoding
83
+
84
+ # Percent-encodes a value according to OAuth specification
85
+ def self.escape: (String | _ToS value) -> String
86
+
87
+ # Alias for escape
88
+ def self.encode: (String | _ToS value) -> String
89
+
90
+ # Decodes a percent-encoded value
91
+ def self.unescape: (String | _ToS value) -> String
92
+
93
+ # Alias for unescape
94
+ def self.decode: (String | _ToS value) -> String
95
+
96
+ # Creates a new OAuth header
97
+ def initialize: (String | Symbol method, String | URI::Generic url, params_hash params, ?oauth_options | String oauth, ?String? body) -> void
98
+
99
+ # Returns the normalized URL without query string or fragment
100
+ def url: () -> String
101
+
102
+ # Returns the OAuth Authorization header string
103
+ def to_s: () -> String
104
+
105
+ # Validates the signature in the header against the provided secrets
106
+ def valid?: (?oauth_options secrets) -> bool
107
+
108
+ # Returns the OAuth attributes including the signature
109
+ def signed_attributes: () -> signed_attributes_hash
110
+
111
+ private
112
+
113
+ # Internal URI instance
114
+ @uri: URI::Generic
115
+
116
+ # Normalizes and parses a URL into a URI object
117
+ def normalize_uri: (String | URI::Generic url) -> URI::Generic
118
+
119
+ # Builds OAuth options from input (hash or header string)
120
+ def build_options: (oauth_options | String oauth, String? body) -> oauth_options
121
+
122
+ # Builds the normalized OAuth attributes string for the Authorization header
123
+ def normalized_attributes: () -> String
124
+
125
+ # Extracts valid OAuth attributes from options (excludes realm per RFC 5849)
126
+ def attributes: () -> signed_attributes_hash
127
+
128
+ # Validates that no unknown keys are present in options
129
+ def validate_option_keys!: () -> void
130
+
131
+ # Returns OAuth attributes including realm for Authorization header output
132
+ def header_attributes: () -> signed_attributes_hash
133
+
134
+ # Extracts query parameters from the request URL
135
+ def url_params: () -> Array[untyped]
136
+
137
+ # Computes the OAuth signature using the configured signature method
138
+ def signature: () -> String
139
+
140
+ # Builds the secret string from consumer and token secrets
141
+ def secret: () -> String
142
+
143
+ # Builds the signature base string from method, URL, and params
144
+ def signature_base: () -> String
145
+
146
+ # Normalizes and sorts all request parameters for signing
147
+ def normalized_params: () -> String
148
+
149
+ # Collects all parameters to include in signature
150
+ def signature_params: () -> Array[untyped]
151
+ end
152
+ end
153
+
154
+ # Version module
155
+ module SimpleOauth
156
+ # The current version of the SimpleOAuth gem
157
+ VERSION: String
158
+ end
data/sig/strscan.rbs ADDED
@@ -0,0 +1,9 @@
1
+ # Minimal StringScanner type declarations for simple_oauth
2
+ class StringScanner
3
+ def initialize: (String string) -> void
4
+ def scan: (Regexp pattern) -> String?
5
+ def eos?: () -> bool
6
+ def rest: () -> String
7
+ def pos: () -> Integer
8
+ def []: (Integer index) -> String?
9
+ end
@@ -0,0 +1,10 @@
1
+ # Stubs for URI module
2
+ module URI
3
+ # The RFC2396 parser instance constant
4
+ RFC2396_PARSER: RFC2396_Parser
5
+
6
+ class Generic
7
+ # Returns the URI as a String (implicit conversion)
8
+ def to_str: () -> String
9
+ end
10
+ end
metadata CHANGED
@@ -1,30 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Richert
8
- - Erik Michaels-Ober
9
- autorequire:
10
- bindir: bin
8
+ - Erik Berlin
9
+ bindir: exe
11
10
  cert_chain: []
12
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: bundler
14
+ name: base64
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - "~>"
17
+ - - ">="
19
18
  - !ruby/object:Gem::Version
20
- version: '1.0'
21
- type: :development
19
+ version: '0'
20
+ type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - "~>"
24
+ - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: '1.0'
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cgi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
28
41
  description: Simply builds and verifies OAuth headers
29
42
  email:
30
43
  - steve.richert@gmail.com
@@ -33,28 +46,40 @@ executables: []
33
46
  extensions: []
34
47
  extra_rdoc_files: []
35
48
  files:
36
- - ".gitignore"
37
- - ".rspec"
38
49
  - ".rubocop.yml"
39
- - ".travis.yml"
40
50
  - ".yardopts"
51
+ - CHANGELOG.md
41
52
  - CONTRIBUTING.md
42
- - Gemfile
43
53
  - LICENSE.md
44
54
  - README.md
45
55
  - Rakefile
56
+ - Steepfile
46
57
  - lib/simple_oauth.rb
58
+ - lib/simple_oauth/encoding.rb
59
+ - lib/simple_oauth/errors.rb
47
60
  - lib/simple_oauth/header.rb
48
- - simple_oauth.gemspec
49
- - spec/helper.rb
50
- - spec/simple_oauth/header_spec.rb
51
- - spec/support/fixtures/rsa-private-key
52
- - spec/support/rsa.rb
61
+ - lib/simple_oauth/header/class_methods.rb
62
+ - lib/simple_oauth/parser.rb
63
+ - lib/simple_oauth/signature.rb
64
+ - lib/simple_oauth/version.rb
65
+ - mutant.yml
66
+ - sig/matchdata_ext.rbs
67
+ - sig/openssl_ext.rbs
68
+ - sig/simple_oauth.rbs
69
+ - sig/simple_oauth/header/class_methods.rbs
70
+ - sig/simple_oauth/parser.rbs
71
+ - sig/simple_oauth/signature.rbs
72
+ - sig/strscan.rbs
73
+ - sig/uri_rfc2396_parser.rbs
53
74
  homepage: https://github.com/laserlemon/simple_oauth
54
75
  licenses:
55
76
  - MIT
56
- metadata: {}
57
- post_install_message:
77
+ metadata:
78
+ allowed_push_host: https://rubygems.org
79
+ homepage_uri: https://github.com/laserlemon/simple_oauth
80
+ source_code_uri: https://github.com/laserlemon/simple_oauth
81
+ changelog_uri: https://github.com/laserlemon/simple_oauth/blob/master/CHANGELOG.md
82
+ rubygems_mfa_required: 'true'
58
83
  rdoc_options: []
59
84
  require_paths:
60
85
  - lib
@@ -62,17 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
87
  requirements:
63
88
  - - ">="
64
89
  - !ruby/object:Gem::Version
65
- version: '0'
90
+ version: '3.2'
66
91
  required_rubygems_version: !ruby/object:Gem::Requirement
67
92
  requirements:
68
93
  - - ">="
69
94
  - !ruby/object:Gem::Version
70
95
  version: '0'
71
96
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.4.1
74
- signing_key:
97
+ rubygems_version: 4.0.5
75
98
  specification_version: 4
76
99
  summary: Simply builds and verifies OAuth headers
77
100
  test_files: []
78
- has_rdoc:
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- *.rbc
2
- .DS_Store
3
- .bundle
4
- .yardoc
5
- Gemfile.lock
6
- coverage
7
- doc
8
- measurement
9
- pkg
10
- rdoc
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --order random
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- env:
3
- global:
4
- - JRUBY_OPTS="$JRUBY_OPTS --debug"
5
- rvm:
6
- - 1.8.7
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1
10
- - jruby-18mode
11
- - jruby-19mode
12
- - jruby-head
13
- - rbx-2
14
- - ruby-head
15
- matrix:
16
- allow_failures:
17
- - rvm: jruby-head
18
- - rvm: rbx-2
19
- - rvm: ruby-head
20
- fast_finish: true
21
- sudo: false
data/Gemfile DELETED
@@ -1,17 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'jruby-openssl', :platforms => :jruby
4
- gem 'rake'
5
-
6
- group :test do
7
- gem 'backports'
8
- gem 'coveralls'
9
- gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
10
- gem 'rest-client', '~> 1.6.0', :platforms => [:jruby, :ruby_18]
11
- gem 'rspec', '>= 2.14'
12
- gem 'rubocop', '>= 0.25', :platforms => [:ruby_19, :ruby_20, :ruby_21]
13
- gem 'simplecov', '>= 0.9'
14
- gem 'yardstick'
15
- end
16
-
17
- gemspec
data/simple_oauth.gemspec DELETED
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |spec|
2
- spec.add_development_dependency 'bundler', '~> 1.0'
3
- spec.name = 'simple_oauth'
4
- spec.version = '0.3.0'
5
-
6
- spec.authors = ['Steve Richert', 'Erik Michaels-Ober']
7
- spec.email = %w(steve.richert@gmail.com sferik@gmail.com)
8
- spec.description = 'Simply builds and verifies OAuth headers'
9
- spec.summary = spec.description
10
- spec.homepage = 'https://github.com/laserlemon/simple_oauth'
11
- spec.licenses = %w(MIT)
12
-
13
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.start_with?('test/') }
14
- spec.require_paths = %w(lib)
15
- end
data/spec/helper.rb DELETED
@@ -1,26 +0,0 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'simplecov'
3
- require 'coveralls'
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
6
-
7
- SimpleCov.start do
8
- add_filter '/spec/'
9
- minimum_coverage(100)
10
- end
11
- end
12
-
13
- require 'simple_oauth'
14
- require 'rspec'
15
-
16
- def uri_parser
17
- @uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
18
- end
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |c|
22
- c.syntax = :expect
23
- end
24
- end
25
-
26
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }