oauth2-core 0.1.1
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/LICENSE +0 -0
- data/README.md +0 -0
- data/lib/oauth2/attributes.rb +58 -0
- data/lib/oauth2/core.rb +6 -0
- data/lib/oauth2/headers.rb +10 -0
- data/lib/oauth2/headers/authenticate.rb +41 -0
- data/lib/oauth2/headers/authorization.rb +93 -0
- metadata +82 -0
data/LICENSE
ADDED
File without changes
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
3
|
+
|
4
|
+
module OAuth2
|
5
|
+
|
6
|
+
module Attributes
|
7
|
+
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
class_inheritable_array :attribute_names
|
12
|
+
self.attribute_names = Array.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
@attributes ||= Hash.new
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
|
21
|
+
# Defines a callback for a handle.
|
22
|
+
def attribute(handle)
|
23
|
+
attribute_names << handle.to_sym
|
24
|
+
|
25
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
26
|
+
def #{handle}(&block)
|
27
|
+
@attributes ||= {}
|
28
|
+
|
29
|
+
if block_given?
|
30
|
+
@attributes[:#{handle}] = block
|
31
|
+
return
|
32
|
+
end
|
33
|
+
|
34
|
+
if value = @attributes[:#{handle}]
|
35
|
+
value.is_a?(Proc) ? value.call : value
|
36
|
+
else
|
37
|
+
raise "No attribute or callback for '#{handle}' defined"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def #{handle.to_s.gsub('?', '')}=(value)
|
42
|
+
@attributes ||= {}
|
43
|
+
@attributes[:#{handle}] = value
|
44
|
+
end
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def attributes(*handles)
|
49
|
+
handles.each do |handle|
|
50
|
+
attribute(handle)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/oauth2/core.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'oauth2/attributes'
|
2
|
+
|
3
|
+
module OAuth2
|
4
|
+
|
5
|
+
module Headers
|
6
|
+
|
7
|
+
class Authenticate
|
8
|
+
|
9
|
+
Attributes = [
|
10
|
+
:realm, :algorithms, :auth_uri, :token_uri, :error
|
11
|
+
]
|
12
|
+
|
13
|
+
Attributes.each do |attribute|
|
14
|
+
attr_accessor attribute
|
15
|
+
end
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
raise "Realm not set" unless realm
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
Attributes.inject(Hash.new) do |hash, attribute|
|
24
|
+
value = send(attribute)
|
25
|
+
hash[attribute] = value unless value.nil?
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
to_hash.collect do |key, value|
|
32
|
+
name = key.to_s.gsub('_', '-')
|
33
|
+
"#{name}='#{value}'"
|
34
|
+
end.join(",\n ")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'oauth2/attributes'
|
2
|
+
|
3
|
+
module OAuth2
|
4
|
+
|
5
|
+
module Headers
|
6
|
+
|
7
|
+
class Authorization
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
attributes.each_pair do |key, value|
|
11
|
+
if Attributes.include?(key.to_sym)
|
12
|
+
instance_variable_set("@#{key}", value)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# These attributes are expected to be contained in the header
|
18
|
+
Attributes = [
|
19
|
+
:token, :nonce, :timestamp, :algorithm, :signature
|
20
|
+
]
|
21
|
+
|
22
|
+
Attributes.each do |attribute|
|
23
|
+
attr_accessor(attribute)
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate
|
27
|
+
case request_type
|
28
|
+
when :bearer
|
29
|
+
@errors << :bearer_request_requires_token unless token
|
30
|
+
when :cryptographic
|
31
|
+
%w{nonce timestamp algorithm signature}.each do |attribute|
|
32
|
+
unless instance_variable_get("@#{attribute}")
|
33
|
+
error = "cryptographic_request_requires_#{attribute}".to_sym
|
34
|
+
@errors << error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@errors.blank?
|
40
|
+
end
|
41
|
+
|
42
|
+
def errors
|
43
|
+
@errors ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
def attributes
|
47
|
+
Attributes.inject(Hash.new) do |hash, attribute|
|
48
|
+
hash[attribute] = instance_variable_get("@#{attribute}")
|
49
|
+
hash
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class << self
|
54
|
+
|
55
|
+
# This method does what it is named after. Give it a String and it
|
56
|
+
# returns a Hash. The header specification can be found on:
|
57
|
+
# http://tools.ietf.org/html/draft-hammer-oauth2-00#section-5.1
|
58
|
+
# TODO: Use OrderedHash and verify that token is the first parameter
|
59
|
+
def parse(string, attributes = {})
|
60
|
+
header = new(attributes)
|
61
|
+
|
62
|
+
string.strip!
|
63
|
+
|
64
|
+
type, tuples = string[0..4], string[5..-1].split("\n")
|
65
|
+
|
66
|
+
header.errors << :format_invalid unless type == "Token"
|
67
|
+
|
68
|
+
tuples.map! { |tuple| tuple.strip! }
|
69
|
+
|
70
|
+
tuples.each do |tuple|
|
71
|
+
unless tuple =~ /\s*(.+)="(.+)"/
|
72
|
+
header.errors << :format_invalid
|
73
|
+
else
|
74
|
+
key, value = $1.to_sym, $2
|
75
|
+
|
76
|
+
unless Attributes.include?(key)
|
77
|
+
header.errors << "unknown_attribute_#{key}".to_sym
|
78
|
+
else
|
79
|
+
header.send("#{key}=".to_sym, value)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
header
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oauth2-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Alexander Flatter
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-07 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: ""
|
33
|
+
email:
|
34
|
+
- aflatter@farbenmeer.net
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- lib/oauth2/attributes.rb
|
43
|
+
- lib/oauth2/core.rb
|
44
|
+
- lib/oauth2/headers/authenticate.rb
|
45
|
+
- lib/oauth2/headers/authorization.rb
|
46
|
+
- lib/oauth2/headers.rb
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/aflatter/oauth2
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 3
|
72
|
+
- 6
|
73
|
+
version: 1.3.6
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.6
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: ""
|
81
|
+
test_files: []
|
82
|
+
|