authlete 0.3.6 → 0.3.7
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/lib/authlete.rb +14 -14
- data/lib/authlete/api.rb +115 -35
- data/lib/authlete/authentication-server.rb +4 -4
- data/lib/authlete/model/client-list.rb +127 -181
- data/lib/authlete/model/client.rb +444 -492
- data/lib/authlete/model/hashable.rb +65 -0
- data/lib/authlete/model/request/authentication-callback-request.rb +91 -0
- data/lib/authlete/model/request/authorization-fail-request.rb +107 -0
- data/lib/authlete/model/request/authorization-issue-request.rb +136 -0
- data/lib/authlete/model/request/authorization-request.rb +104 -0
- data/lib/authlete/model/request/developer-authentication-callback-request.rb +85 -0
- data/lib/authlete/model/request/introspection-request.rb +40 -0
- data/lib/authlete/model/request/token-fail-request.rb +104 -0
- data/lib/authlete/model/request/token-issue-request.rb +104 -0
- data/lib/authlete/model/request/token-request.rb +124 -0
- data/lib/authlete/model/response/authentication-callback-response.rb +54 -0
- data/lib/authlete/model/response/authorization-fail-response.rb +47 -0
- data/lib/authlete/model/response/authorization-issue-response.rb +47 -0
- data/lib/authlete/model/response/authorization-response.rb +146 -0
- data/lib/authlete/model/response/developer-authentication-callback-response.rb +56 -0
- data/lib/authlete/model/response/introspection-response.rb +129 -0
- data/lib/authlete/model/response/result.rb +45 -0
- data/lib/authlete/model/response/service-creatable-response.rb +51 -0
- data/lib/authlete/model/response/token-fail-response.rb +48 -0
- data/lib/authlete/model/response/token-issue-response.rb +48 -0
- data/lib/authlete/model/response/token-response.rb +69 -0
- data/lib/authlete/model/scope.rb +17 -42
- data/lib/authlete/model/service-list.rb +19 -74
- data/lib/authlete/model/service-owner.rb +16 -40
- data/lib/authlete/model/service.rb +20 -76
- data/lib/authlete/model/sns-credentials.rb +16 -41
- data/lib/authlete/model/tagged-value.rb +105 -135
- data/lib/authlete/utility.rb +29 -5
- data/lib/authlete/version.rb +1 -1
- metadata +24 -10
- data/lib/authlete/request/authentication-callback-request.rb +0 -90
- data/lib/authlete/request/developer-authentication-callback-request.rb +0 -84
- data/lib/authlete/response/authentication-callback-response.rb +0 -58
- data/lib/authlete/response/base-response.rb +0 -41
- data/lib/authlete/response/developer-authentication-callback-response.rb +0 -60
- data/lib/authlete/response/introspection-response.rb +0 -130
- data/lib/authlete/response/service-creatable-response.rb +0 -52
@@ -0,0 +1,85 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2015 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 'json'
|
19
|
+
|
20
|
+
|
21
|
+
module Authlete
|
22
|
+
module Model
|
23
|
+
module Request
|
24
|
+
# == Authlete::Model::Request::DeveloperAuthenticationCallbackRequest class
|
25
|
+
#
|
26
|
+
# This class represents a request to a developer authentication callback endpoint.
|
27
|
+
class DeveloperAuthenticationCallbackRequest
|
28
|
+
include Authlete::Utility
|
29
|
+
# The API key of the service.
|
30
|
+
attr_accessor :service_api_key
|
31
|
+
|
32
|
+
# The login ID that the developer input to the login ID field.
|
33
|
+
# When 'sns' attribute is not nil, this attribute holds the
|
34
|
+
# subject (= unique identifier) of the developer in the SNS.
|
35
|
+
attr_accessor :id
|
36
|
+
|
37
|
+
# The password that the developer input to the password field.
|
38
|
+
# If 'sns' property is nil, it is ensured that this attribute
|
39
|
+
# is not nil. In such a case, authentication should be performed
|
40
|
+
# on the pair of 'id' attribute and this 'password' attribute.
|
41
|
+
# On the other hand, if 'sns' attribute is not nil, this attribute
|
42
|
+
# has no meaning, because authentication has performed by the SNS.
|
43
|
+
attr_accessor :password
|
44
|
+
|
45
|
+
# The SNS which the developer used for social login.
|
46
|
+
# For example, 'FACEBOOK'.
|
47
|
+
attr_accessor :sns
|
48
|
+
|
49
|
+
# The access token issued at the token endpoint of the SNS.
|
50
|
+
attr_accessor :access_token
|
51
|
+
|
52
|
+
# The refresh token issued along with the access token.
|
53
|
+
attr_accessor :refresh_token
|
54
|
+
|
55
|
+
# The duration of the access token.
|
56
|
+
attr_accessor :expires_in
|
57
|
+
|
58
|
+
# The raw content of the response from the token endpoint of the SNS.
|
59
|
+
# Correct OAuth 2.0 implementations return 'application/json', but
|
60
|
+
# Facebook returns 'application/x-www-form-url-encoded'.
|
61
|
+
attr_accessor :raw_token_response
|
62
|
+
|
63
|
+
# The constructor which takes a hash that represents a JSON request
|
64
|
+
# to a developer authentication callback endpoint.
|
65
|
+
def initialize(hash = {})
|
66
|
+
@service_api_key = extract_value(hash, :serviceApiKey)
|
67
|
+
@id = extract_value(hash, :id)
|
68
|
+
@password = extract_value(hash, :password)
|
69
|
+
@sns = extract_value(hash, :sns)
|
70
|
+
@access_token = extract_value(hash, :accessToken)
|
71
|
+
@refresh_token = extract_value(hash, :refreshToken)
|
72
|
+
@expires_in = extract_integer_value(hash, :expiresIn)
|
73
|
+
@raw_token_response = extract_value(hash, :rawTokenResponse)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Parse a JSON string which represents a request to a developer
|
77
|
+
# authentication callback endpoint and generate an instance of
|
78
|
+
# DeveloperAuthenticationCallbackRequest.
|
79
|
+
def self.parse(json)
|
80
|
+
DeveloperAuthenticationCallbackRequest.new(JSON.parse(json))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2015 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 Model
|
20
|
+
module Request
|
21
|
+
# == Authlete::Model::Request::IntrospectionRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/introspection API.
|
24
|
+
class IntrospectionRequest
|
25
|
+
include Authlete::Utility
|
26
|
+
# The constructor which takes a hash that represents a JSON request
|
27
|
+
# to Authlete's /api/auth/introspection API.
|
28
|
+
def initialize(hash = {})
|
29
|
+
end
|
30
|
+
|
31
|
+
# Parse a JSON string which represents a request to
|
32
|
+
# Authlete's /api/auth/introspection API
|
33
|
+
# and generate an instance of IntrospectionRequest.
|
34
|
+
def self.parse(json)
|
35
|
+
IntrospectionRequest.new(parse_json(json))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2015 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 Model
|
20
|
+
module Request
|
21
|
+
# == Authlete::Model::Request::TokenFailRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/token/fail API.
|
24
|
+
class TokenFailRequest < Authlete::Model::Hashable
|
25
|
+
# The ticket issued by Authlete's /api/auth/token API. (String)
|
26
|
+
attr_accessor :ticket
|
27
|
+
|
28
|
+
# The reason of the failure. (String)
|
29
|
+
attr_accessor :reason
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# String attributes.
|
34
|
+
STRING_ATTRIBUTES = ::Set.new([ :ticket, :reason ])
|
35
|
+
|
36
|
+
# The constructor which takes a hash that represents a JSON request to
|
37
|
+
# Authlete's /api/auth/token/fail API.
|
38
|
+
def initialize(hash = {})
|
39
|
+
super
|
40
|
+
|
41
|
+
# Set default values to string attributes.
|
42
|
+
STRING_ATTRIBUTES.each do |attr|
|
43
|
+
send("#{attr}=", nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set attribute values using the given hash.
|
47
|
+
authlete_model_update(hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
def authlete_model_convert_key(key)
|
51
|
+
key.to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
def authlete_model_simple_attribute?(key)
|
55
|
+
STRING_ATTRIBUTES.include?(key)
|
56
|
+
end
|
57
|
+
|
58
|
+
def authlete_model_update(hash)
|
59
|
+
return if hash.nil?
|
60
|
+
|
61
|
+
hash.each do |key, value|
|
62
|
+
key = authlete_model_convert_key(key)
|
63
|
+
|
64
|
+
if authlete_model_simple_attribute?(key)
|
65
|
+
send("#{key}=", value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
public
|
73
|
+
|
74
|
+
# Construct an instance from the given hash.
|
75
|
+
#
|
76
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
77
|
+
# Otherwise, TokenFailRequest.new(hash) is returned.
|
78
|
+
def self.parse(hash)
|
79
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
|
83
|
+
return TokenFailRequest.new(hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Convert this object into a hash.
|
87
|
+
def to_hash
|
88
|
+
hash = {}
|
89
|
+
|
90
|
+
instance_variables.each do |var|
|
91
|
+
key = var.to_s.delete("@").to_sym
|
92
|
+
val = instance_variable_get(var)
|
93
|
+
|
94
|
+
if authlete_model_simple_attribute?(key) or val.nil?
|
95
|
+
hash[key] = val
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
hash
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2015 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 Model
|
20
|
+
module Request
|
21
|
+
# == Authlete::Model::Request::TokenIssueRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/token/issue API.
|
24
|
+
class TokenIssueRequest < Authlete::Model::Hashable
|
25
|
+
# The ticket issued by Authlete's /api/auth/authorization API. (String)
|
26
|
+
attr_accessor :ticket
|
27
|
+
|
28
|
+
# The subject (end-user) managed by the service. (String)
|
29
|
+
attr_accessor :subject
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# String attributes.
|
34
|
+
STRING_ATTRIBUTES = ::Set.new([ :ticket, :subject ])
|
35
|
+
|
36
|
+
# The constructor which takes a hash that represents a JSON request to
|
37
|
+
# Authlete's /api/auth/token/issue API.
|
38
|
+
def initialize(hash = {})
|
39
|
+
super
|
40
|
+
|
41
|
+
# Set default values to string attributes.
|
42
|
+
STRING_ATTRIBUTES.each do |attr|
|
43
|
+
send("#{attr}=", nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Set attribute values using the given hash.
|
47
|
+
authlete_model_update(hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
def authlete_model_convert_key(key)
|
51
|
+
key.to_sym
|
52
|
+
end
|
53
|
+
|
54
|
+
def authlete_model_simple_attribute?(key)
|
55
|
+
STRING_ATTRIBUTES.include?(key)
|
56
|
+
end
|
57
|
+
|
58
|
+
def authlete_model_update(hash)
|
59
|
+
return if hash.nil?
|
60
|
+
|
61
|
+
hash.each do |key, value|
|
62
|
+
key = authlete_model_convert_key(key)
|
63
|
+
|
64
|
+
if authlete_model_simple_attribute?(key)
|
65
|
+
send("#{key}=", value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
public
|
73
|
+
|
74
|
+
# Construct an instance from the given hash.
|
75
|
+
#
|
76
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
77
|
+
# Otherwise, TokenIssueRequest.new(hash) is returned.
|
78
|
+
def self.parse(hash)
|
79
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
80
|
+
return nil
|
81
|
+
end
|
82
|
+
|
83
|
+
return TokenIssueRequest.new(hash)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Convert this object into a hash.
|
87
|
+
def to_hash
|
88
|
+
hash = {}
|
89
|
+
|
90
|
+
instance_variables.each do |var|
|
91
|
+
key = var.to_s.delete("@").to_sym
|
92
|
+
val = instance_variable_get(var)
|
93
|
+
|
94
|
+
if authlete_model_simple_attribute?(key) or val.nil?
|
95
|
+
hash[key] = val
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
hash
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2015 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 Model
|
20
|
+
module Request
|
21
|
+
# == Authlete::Model::Request::TokenRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/token API.
|
24
|
+
class TokenRequest < Authlete::Model::Hashable
|
25
|
+
# OAuth 2.0 token request parameters. (String)
|
26
|
+
attr_accessor :parameters
|
27
|
+
|
28
|
+
# Client ID. (String)
|
29
|
+
attr_accessor :clientId
|
30
|
+
alias_method :client_id, :clientId
|
31
|
+
alias_method :client_id=, :clientId=
|
32
|
+
|
33
|
+
# Client Secret. (String)
|
34
|
+
attr_accessor :clientSecret
|
35
|
+
alias_method :client_secret, :clientSecret
|
36
|
+
alias_method :client_secret=, :clientSecret=
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# String attributes.
|
41
|
+
STRING_ATTRIBUTES = ::Set.new([ :parameters, :clientId, :clientSecret ])
|
42
|
+
|
43
|
+
# Mapping from snake cases to camel cases.
|
44
|
+
SNAKE_TO_CAMEL = {
|
45
|
+
:client_id => :clientId,
|
46
|
+
:client_secret => :clientSecret
|
47
|
+
}
|
48
|
+
|
49
|
+
# The constructor which takes a hash that represents a JSON request
|
50
|
+
# to Authlete's /api/auth/token API.
|
51
|
+
def initialize(hash = {})
|
52
|
+
super
|
53
|
+
|
54
|
+
# Set default values to string attributes.
|
55
|
+
STRING_ATTRIBUTES.each do |attr|
|
56
|
+
send("#{attr}=", nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set attribute values using the given hash.
|
60
|
+
authlete_model_update(hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
def authlete_model_convert_key(key)
|
64
|
+
key = key.to_sym
|
65
|
+
|
66
|
+
# Convert snakecase to camelcase, if necessary.
|
67
|
+
if SNAKE_TO_CAMEL.has_key?(key)
|
68
|
+
key = SNAKE_TO_CAMEL[key]
|
69
|
+
end
|
70
|
+
|
71
|
+
key
|
72
|
+
end
|
73
|
+
|
74
|
+
def authlete_model_simple_attribute?(key)
|
75
|
+
STRING_ATTRIBUTES.include?(key)
|
76
|
+
end
|
77
|
+
|
78
|
+
def authlete_model_update(hash)
|
79
|
+
return if hash.nil?
|
80
|
+
|
81
|
+
hash.each do |key, value|
|
82
|
+
key = authlete_model_convert_key(key)
|
83
|
+
|
84
|
+
if authlete_model_simple_attribute?(key)
|
85
|
+
send("#{key}=", value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
public
|
93
|
+
|
94
|
+
# Construct an instance from the given hash.
|
95
|
+
#
|
96
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
97
|
+
# Otherwise, TokenRequest.new(hash) is returned.
|
98
|
+
def self.parse(hash)
|
99
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
100
|
+
return nil
|
101
|
+
end
|
102
|
+
|
103
|
+
return TokenRequest.new(hash)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Convert this object into a hash.
|
107
|
+
def to_hash
|
108
|
+
hash = {}
|
109
|
+
|
110
|
+
instance_variables.each do |var|
|
111
|
+
key = var.to_s.delete("@").to_sym
|
112
|
+
val = instance_variable_get(var)
|
113
|
+
|
114
|
+
if authlete_model_simple_attribute?(key) or val.nil?
|
115
|
+
hash[key] = val
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
hash
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|