authlete 1.0.19 → 1.0.24
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.
- checksums.yaml +4 -4
- data/README.md +20 -20
- data/lib/authlete/api.rb +8 -2
- data/lib/authlete/authentication-server.rb +229 -229
- data/lib/authlete/model/client.rb +73 -59
- data/lib/authlete/model/scope.rb +157 -157
- data/lib/authlete/model/service-list.rb +127 -127
- data/lib/authlete/model/service.rb +880 -787
- data/lib/authlete/model/sns-credentials.rb +123 -123
- data/lib/authlete/utility.rb +98 -98
- data/lib/authlete/version.rb +1 -1
- metadata +7 -7
@@ -1,124 +1,124 @@
|
|
1
|
-
# :nodoc:
|
2
|
-
#
|
3
|
-
# Copyright (C) 2014-2018 Authlete, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
require 'set'
|
19
|
-
|
20
|
-
|
21
|
-
module Authlete
|
22
|
-
module Model
|
23
|
-
class SnsCredentials < Authlete::Model::Hashable
|
24
|
-
# The API key. (String)
|
25
|
-
attr_accessor :apiKey
|
26
|
-
alias_method :api_key, :apiKey
|
27
|
-
alias_method :api_key=, :apiKey=
|
28
|
-
|
29
|
-
# The API secret. (String)
|
30
|
-
attr_accessor :apiSecret
|
31
|
-
alias_method :api_secret, :apiSecret
|
32
|
-
alias_method :api_secret=, :apiSecret=
|
33
|
-
|
34
|
-
# The SNS. (String)
|
35
|
-
#
|
36
|
-
# Currently, the only valid value is "FACEBOOK".
|
37
|
-
attr_accessor :sns
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
# String attributes.
|
42
|
-
STRING_ATTRIBUTES = ::Set.new([ :apiKey, :apiSecret, :sns ])
|
43
|
-
|
44
|
-
# Mapping from snake cases to camel cases.
|
45
|
-
SNAKE_TO_CAMEL = {
|
46
|
-
:api_key => :apiKey,
|
47
|
-
:api_secret => :apiSecret
|
48
|
-
}
|
49
|
-
|
50
|
-
# The constructor.
|
51
|
-
def initialize(hash = nil)
|
52
|
-
# Set default values to string attributes.
|
53
|
-
STRING_ATTRIBUTES.each do |attr|
|
54
|
-
send("#{attr}=", nil)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Set attribute values using the given hash.
|
58
|
-
authlete_model_update(hash)
|
59
|
-
end
|
60
|
-
|
61
|
-
def authlete_model_convert_key(key)
|
62
|
-
key = key.to_sym
|
63
|
-
|
64
|
-
# Convert snakecase to camelcase, if necessary.
|
65
|
-
if SNAKE_TO_CAMEL.has_key?(key)
|
66
|
-
key = SNAKE_TO_CAMEL[key]
|
67
|
-
end
|
68
|
-
|
69
|
-
key
|
70
|
-
end
|
71
|
-
|
72
|
-
def authlete_model_simple_attribute?(key)
|
73
|
-
STRING_ATTRIBUTES.include?(key)
|
74
|
-
end
|
75
|
-
|
76
|
-
def authlete_model_update(hash)
|
77
|
-
return if hash.nil?
|
78
|
-
|
79
|
-
hash.each do |key, value|
|
80
|
-
key = authlete_model_convert_key(key)
|
81
|
-
|
82
|
-
if authlete_model_simple_attribute?(key)
|
83
|
-
send("#{key}=", value)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
self
|
88
|
-
end
|
89
|
-
|
90
|
-
public
|
91
|
-
|
92
|
-
# Construct an instance from the given hash.
|
93
|
-
#
|
94
|
-
# If the given argument is nil or is not a Hash, nil is returned.
|
95
|
-
# Otherwise, SnsCredentials.new(hash) is returned.
|
96
|
-
def self.parse(hash)
|
97
|
-
if hash.nil? or (hash.kind_of?(Hash) == false)
|
98
|
-
return nil
|
99
|
-
end
|
100
|
-
|
101
|
-
Authlete::Model::SnsCredentials.new(hash)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Set attribute values using the given hash.
|
105
|
-
def update(hash)
|
106
|
-
authlete_model_update(hash)
|
107
|
-
end
|
108
|
-
|
109
|
-
# Convert this object into a hash.
|
110
|
-
def to_hash
|
111
|
-
hash = {}
|
112
|
-
|
113
|
-
instance_variables.each do |var|
|
114
|
-
key = var.to_s.delete("@").to_sym
|
115
|
-
val = instance_variable_get(var)
|
116
|
-
|
117
|
-
hash[key] = val
|
118
|
-
end
|
119
|
-
|
120
|
-
hash
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2018 Authlete, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
require 'set'
|
19
|
+
|
20
|
+
|
21
|
+
module Authlete
|
22
|
+
module Model
|
23
|
+
class SnsCredentials < Authlete::Model::Hashable
|
24
|
+
# The API key. (String)
|
25
|
+
attr_accessor :apiKey
|
26
|
+
alias_method :api_key, :apiKey
|
27
|
+
alias_method :api_key=, :apiKey=
|
28
|
+
|
29
|
+
# The API secret. (String)
|
30
|
+
attr_accessor :apiSecret
|
31
|
+
alias_method :api_secret, :apiSecret
|
32
|
+
alias_method :api_secret=, :apiSecret=
|
33
|
+
|
34
|
+
# The SNS. (String)
|
35
|
+
#
|
36
|
+
# Currently, the only valid value is "FACEBOOK".
|
37
|
+
attr_accessor :sns
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# String attributes.
|
42
|
+
STRING_ATTRIBUTES = ::Set.new([ :apiKey, :apiSecret, :sns ])
|
43
|
+
|
44
|
+
# Mapping from snake cases to camel cases.
|
45
|
+
SNAKE_TO_CAMEL = {
|
46
|
+
:api_key => :apiKey,
|
47
|
+
:api_secret => :apiSecret
|
48
|
+
}
|
49
|
+
|
50
|
+
# The constructor.
|
51
|
+
def initialize(hash = nil)
|
52
|
+
# Set default values to string attributes.
|
53
|
+
STRING_ATTRIBUTES.each do |attr|
|
54
|
+
send("#{attr}=", nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set attribute values using the given hash.
|
58
|
+
authlete_model_update(hash)
|
59
|
+
end
|
60
|
+
|
61
|
+
def authlete_model_convert_key(key)
|
62
|
+
key = key.to_sym
|
63
|
+
|
64
|
+
# Convert snakecase to camelcase, if necessary.
|
65
|
+
if SNAKE_TO_CAMEL.has_key?(key)
|
66
|
+
key = SNAKE_TO_CAMEL[key]
|
67
|
+
end
|
68
|
+
|
69
|
+
key
|
70
|
+
end
|
71
|
+
|
72
|
+
def authlete_model_simple_attribute?(key)
|
73
|
+
STRING_ATTRIBUTES.include?(key)
|
74
|
+
end
|
75
|
+
|
76
|
+
def authlete_model_update(hash)
|
77
|
+
return if hash.nil?
|
78
|
+
|
79
|
+
hash.each do |key, value|
|
80
|
+
key = authlete_model_convert_key(key)
|
81
|
+
|
82
|
+
if authlete_model_simple_attribute?(key)
|
83
|
+
send("#{key}=", value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
public
|
91
|
+
|
92
|
+
# Construct an instance from the given hash.
|
93
|
+
#
|
94
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
95
|
+
# Otherwise, SnsCredentials.new(hash) is returned.
|
96
|
+
def self.parse(hash)
|
97
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
98
|
+
return nil
|
99
|
+
end
|
100
|
+
|
101
|
+
Authlete::Model::SnsCredentials.new(hash)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Set attribute values using the given hash.
|
105
|
+
def update(hash)
|
106
|
+
authlete_model_update(hash)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Convert this object into a hash.
|
110
|
+
def to_hash
|
111
|
+
hash = {}
|
112
|
+
|
113
|
+
instance_variables.each do |var|
|
114
|
+
key = var.to_s.delete("@").to_sym
|
115
|
+
val = instance_variable_get(var)
|
116
|
+
|
117
|
+
hash[key] = val
|
118
|
+
end
|
119
|
+
|
120
|
+
hash
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
124
|
end
|
data/lib/authlete/utility.rb
CHANGED
@@ -1,99 +1,99 @@
|
|
1
|
-
# :nodoc:
|
2
|
-
#
|
3
|
-
# Copyright (C) 2014-2018 Authlete, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
|
18
|
-
module Authlete
|
19
|
-
module Utility
|
20
|
-
def extract_value(hash, key)
|
21
|
-
if hash.has_key?(key)
|
22
|
-
hash[key]
|
23
|
-
else
|
24
|
-
hash[key.to_s]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def extract_integer_value(hash, key)
|
29
|
-
extract_value(hash, key).to_i
|
30
|
-
end
|
31
|
-
|
32
|
-
def extract_boolean_value(hash, key)
|
33
|
-
value = extract_value(hash, key)
|
34
|
-
(value == true || value == 'true')
|
35
|
-
end
|
36
|
-
|
37
|
-
def extract_array_value(hash, key)
|
38
|
-
array = extract_value(hash, key)
|
39
|
-
|
40
|
-
# Parse each of the elements in the array.
|
41
|
-
# Then, put them into an array.
|
42
|
-
get_parsed_array(array) do |element|
|
43
|
-
yield(element)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Extract an access token (RFC 6750)
|
48
|
-
def extract_access_token(request)
|
49
|
-
header = request.env['HTTP_AUTHORIZATION']
|
50
|
-
|
51
|
-
if /^Bearer[ ]+(.+)/i =~ header
|
52
|
-
return $1
|
53
|
-
end
|
54
|
-
|
55
|
-
request['access_token']
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_parsed_array(array)
|
59
|
-
if array.nil? or (array.kind_of?(Array) == false) or (array.empty?)
|
60
|
-
return nil
|
61
|
-
end
|
62
|
-
|
63
|
-
elements = []
|
64
|
-
|
65
|
-
array.each do |element|
|
66
|
-
parsed_element = yield(element)
|
67
|
-
elements.push(parsed_element) unless parsed_element.nil?
|
68
|
-
end
|
69
|
-
|
70
|
-
elements.empty? ? nil : elements
|
71
|
-
end
|
72
|
-
|
73
|
-
def to_rack_response_json(status_code, content)
|
74
|
-
[
|
75
|
-
status_code,
|
76
|
-
{
|
77
|
-
'Content-Type' => 'application/json;charset=UTF-8',
|
78
|
-
'Cache-Control' => 'no-store',
|
79
|
-
'Pragma' => 'no-cache'
|
80
|
-
},
|
81
|
-
[
|
82
|
-
content
|
83
|
-
]
|
84
|
-
]
|
85
|
-
end
|
86
|
-
|
87
|
-
def to_rack_response_www_authenticate(status_code, content)
|
88
|
-
[
|
89
|
-
status_code,
|
90
|
-
{
|
91
|
-
'WWW-Authenticate' => content,
|
92
|
-
'Cache-Control' => 'no-store',
|
93
|
-
'Pragma' => 'no-cache'
|
94
|
-
},
|
95
|
-
nil
|
96
|
-
]
|
97
|
-
end
|
98
|
-
end
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2018 Authlete, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
|
18
|
+
module Authlete
|
19
|
+
module Utility
|
20
|
+
def extract_value(hash, key)
|
21
|
+
if hash.has_key?(key)
|
22
|
+
hash[key]
|
23
|
+
else
|
24
|
+
hash[key.to_s]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_integer_value(hash, key)
|
29
|
+
extract_value(hash, key).to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def extract_boolean_value(hash, key)
|
33
|
+
value = extract_value(hash, key)
|
34
|
+
(value == true || value == 'true')
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract_array_value(hash, key)
|
38
|
+
array = extract_value(hash, key)
|
39
|
+
|
40
|
+
# Parse each of the elements in the array.
|
41
|
+
# Then, put them into an array.
|
42
|
+
get_parsed_array(array) do |element|
|
43
|
+
yield(element)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Extract an access token (RFC 6750)
|
48
|
+
def extract_access_token(request)
|
49
|
+
header = request.env['HTTP_AUTHORIZATION']
|
50
|
+
|
51
|
+
if /^Bearer[ ]+(.+)/i =~ header
|
52
|
+
return $1
|
53
|
+
end
|
54
|
+
|
55
|
+
request['access_token']
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_parsed_array(array)
|
59
|
+
if array.nil? or (array.kind_of?(Array) == false) or (array.empty?)
|
60
|
+
return nil
|
61
|
+
end
|
62
|
+
|
63
|
+
elements = []
|
64
|
+
|
65
|
+
array.each do |element|
|
66
|
+
parsed_element = yield(element)
|
67
|
+
elements.push(parsed_element) unless parsed_element.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
elements.empty? ? nil : elements
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_rack_response_json(status_code, content)
|
74
|
+
[
|
75
|
+
status_code,
|
76
|
+
{
|
77
|
+
'Content-Type' => 'application/json;charset=UTF-8',
|
78
|
+
'Cache-Control' => 'no-store',
|
79
|
+
'Pragma' => 'no-cache'
|
80
|
+
},
|
81
|
+
[
|
82
|
+
content
|
83
|
+
]
|
84
|
+
]
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_rack_response_www_authenticate(status_code, content)
|
88
|
+
[
|
89
|
+
status_code,
|
90
|
+
{
|
91
|
+
'WWW-Authenticate' => content,
|
92
|
+
'Cache-Control' => 'no-store',
|
93
|
+
'Pragma' => 'no-cache'
|
94
|
+
},
|
95
|
+
nil
|
96
|
+
]
|
97
|
+
end
|
98
|
+
end
|
99
99
|
end
|
data/lib/authlete/version.rb
CHANGED