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,65 @@
|
|
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
|
+
class Hashable
|
21
|
+
private
|
22
|
+
|
23
|
+
def authlete_model_convert_key(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def authelte_model_simple_attribute?(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def authlete_model_update(hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
public
|
33
|
+
|
34
|
+
# Convert this object into a hash.
|
35
|
+
def to_hash
|
36
|
+
end
|
37
|
+
|
38
|
+
# Set attribute values using the given hash.
|
39
|
+
def update(hash = {})
|
40
|
+
authlete_model_update(hash)
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](key)
|
44
|
+
key = authlete_model_convert_key(key)
|
45
|
+
|
46
|
+
if respond_to?(key)
|
47
|
+
send(key)
|
48
|
+
else
|
49
|
+
nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def []=(key, value)
|
54
|
+
key = authlete_model_convert_key(key)
|
55
|
+
method = "#{key}="
|
56
|
+
|
57
|
+
if respond_to?(method)
|
58
|
+
send(method, value)
|
59
|
+
else
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,91 @@
|
|
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::AuthenticationCallbackRequest class
|
25
|
+
#
|
26
|
+
# This class represents a request to an authentication callback endpoint.
|
27
|
+
class AuthenticationCallbackRequest
|
28
|
+
include Authlete::Utility
|
29
|
+
# The API key of the service.
|
30
|
+
attr_accessor :service_api_key
|
31
|
+
|
32
|
+
# The ID of the client application which has triggered the authentication
|
33
|
+
# callback request.
|
34
|
+
attr_accessor :client_id
|
35
|
+
|
36
|
+
# The login ID that the end-user input to the login ID field.
|
37
|
+
attr_accessor :id
|
38
|
+
|
39
|
+
# The password that the end-user input to the password field.
|
40
|
+
attr_accessor :password
|
41
|
+
|
42
|
+
# Names of requested claims (string array).
|
43
|
+
attr_accessor :claims
|
44
|
+
|
45
|
+
# Names of requested claim locales (string array). The values come
|
46
|
+
# from 'claims_locales' request parameter of an authorization request.
|
47
|
+
attr_accessor :claims_locales
|
48
|
+
|
49
|
+
# The SNS which the end-user used for social login.
|
50
|
+
# For example, 'FACEBOOK'.
|
51
|
+
attr_accessor :sns
|
52
|
+
|
53
|
+
# The access token issued at the token endpoint of the SNS.
|
54
|
+
attr_accessor :access_token
|
55
|
+
|
56
|
+
# The refresh token issued along with the access token.
|
57
|
+
attr_accessor :refresh_token
|
58
|
+
|
59
|
+
# The duration of the access token.
|
60
|
+
attr_accessor :expires_in
|
61
|
+
|
62
|
+
# The raw content of the response from the token endpoint of the SNS.
|
63
|
+
# Correct OAuth 2.0 implementations return 'application/json', but Facebook
|
64
|
+
# returns 'application/x-www-form-url-encoded'.
|
65
|
+
attr_accessor :raw_token_response
|
66
|
+
|
67
|
+
# The constructor which takes a hash that represents a JSON request
|
68
|
+
# to an authentication callback endpoint.
|
69
|
+
def initialize(hash = {})
|
70
|
+
@service_api_key = extract_value(hash, :serviceApiKey)
|
71
|
+
@client_id = extract_value(hash, :clientId)
|
72
|
+
@id = extract_value(hash, :id)
|
73
|
+
@password = extract_value(hash, :password)
|
74
|
+
@claims = extract_value(hash, :claims)
|
75
|
+
@claims_locales = extract_value(hash, :claimsLocales)
|
76
|
+
@sns = extract_value(hash, :sns)
|
77
|
+
@access_token = extract_value(hash, :accessToken)
|
78
|
+
@refresh_token = extract_value(hash, :refreshToken)
|
79
|
+
@expires_in = extract_integer_value(hash, :expiresIn)
|
80
|
+
@raw_token_response = extract_value(hash, :rawTokenResponse)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Parse a JSON string which represents a request to an authentication
|
84
|
+
# callback endpoint and generate an instance of AuthenticationCallbackRequest.
|
85
|
+
def self.parse(json)
|
86
|
+
AuthenticationCallbackRequest.new(JSON.parse(json))
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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::AuthorizationFailRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/authorization/fail API.
|
24
|
+
class AuthorizationFailRequest < Authlete::Model::Hashable
|
25
|
+
# The ticket issued by Authlete's /api/auth/authorization API. (String)
|
26
|
+
attr_accessor :ticket
|
27
|
+
|
28
|
+
# The reason of the failure. (String)
|
29
|
+
attr_accessor :reason
|
30
|
+
|
31
|
+
# The custom description about the failure. (String)
|
32
|
+
attr_accessor :description
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# String attributes.
|
37
|
+
STRING_ATTRIBUTES = ::Set.new([ :ticket, :reason, :description ])
|
38
|
+
|
39
|
+
# The constructor which takes a hash that represents a JSON request to
|
40
|
+
# Authlete's /api/auth/authorization/fail API.
|
41
|
+
def initialize(hash = {})
|
42
|
+
super
|
43
|
+
|
44
|
+
# Set default values to string attributes.
|
45
|
+
STRING_ATTRIBUTES.each do |attr|
|
46
|
+
send("#{attr}=", nil)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Set attribute values using the given hash.
|
50
|
+
authlete_model_update(hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
def authlete_model_convert_key(key)
|
54
|
+
key.to_sym
|
55
|
+
end
|
56
|
+
|
57
|
+
def authlete_model_simple_attribute?(key)
|
58
|
+
STRING_ATTRIBUTES.include?(key)
|
59
|
+
end
|
60
|
+
|
61
|
+
def authlete_model_update(hash)
|
62
|
+
return if hash.nil?
|
63
|
+
|
64
|
+
hash.each do |key, value|
|
65
|
+
key = authlete_model_convert_key(key)
|
66
|
+
|
67
|
+
if authlete_model_simple_attribute?(key)
|
68
|
+
send("#{key}=", value)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
public
|
76
|
+
|
77
|
+
# Construct an instance from the given hash.
|
78
|
+
#
|
79
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
80
|
+
# Otherwise, AuthorizationFailRequest.new(hash) is returned.
|
81
|
+
def self.parse(hash)
|
82
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
|
86
|
+
return AuthorizationFailRequest.new(hash)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Convert this object into a hash.
|
90
|
+
def to_hash
|
91
|
+
hash = {}
|
92
|
+
|
93
|
+
instance_variables.each do |var|
|
94
|
+
key = var.to_s.delete("@").to_sym
|
95
|
+
val = instance_variable_get(var)
|
96
|
+
|
97
|
+
if authlete_model_simple_attribute?(key) or val.nil?
|
98
|
+
hash[key] = val
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
hash
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,136 @@
|
|
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::AuthorizationIssueRequest class
|
22
|
+
#
|
23
|
+
# This class represents a request to Authlete's /api/auth/authorization/issue API.
|
24
|
+
class AuthorizationIssueRequest < 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
|
+
# The time when the end-user was authenticated. (Integer)
|
32
|
+
attr_accessor :authTime
|
33
|
+
alias_method :auth_time, :authTime
|
34
|
+
alias_method :auth_time=, :authTime=
|
35
|
+
|
36
|
+
# The authentication context class reference. (String)
|
37
|
+
attr_accessor :acr
|
38
|
+
|
39
|
+
# Claims in JSON format. (String)
|
40
|
+
attr_accessor :claims
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Integer attributes.
|
45
|
+
INTEGER_ATTRIBUTES = ::Set.new([ :authTime ])
|
46
|
+
|
47
|
+
# String attributes.
|
48
|
+
STRING_ATTRIBUTES = ::Set.new([ :ticket, :subject, :acr, :claims ])
|
49
|
+
|
50
|
+
# Mapping from snake cases to camel cases.
|
51
|
+
SNAKE_TO_CAMEL = {
|
52
|
+
:auth_time => :authTime
|
53
|
+
}
|
54
|
+
|
55
|
+
# The constructor which takes a hash that represents a JSON request to
|
56
|
+
# Authlete's /api/auth/authorization/issue API.
|
57
|
+
def initialize(hash = {})
|
58
|
+
super
|
59
|
+
|
60
|
+
# Set default values to integer attributes.
|
61
|
+
INTEGER_ATTRIBUTES.each do |attr|
|
62
|
+
send("#{attr}=", 0)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set default values to string attributes.
|
66
|
+
STRING_ATTRIBUTES.each do |attr|
|
67
|
+
send("#{attr}=", nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Set attribute values using the given hash.
|
71
|
+
authlete_model_update(hash)
|
72
|
+
end
|
73
|
+
|
74
|
+
def authlete_model_convert_key(key)
|
75
|
+
key = key.to_sym
|
76
|
+
|
77
|
+
# Convert snakecase to camelcase, if necessary.
|
78
|
+
if SNAKE_TO_CAMEL.has_key?(key)
|
79
|
+
key = SNAKE_TO_CAMEL[key]
|
80
|
+
end
|
81
|
+
|
82
|
+
key
|
83
|
+
end
|
84
|
+
|
85
|
+
def authlete_model_simple_attribute?(key)
|
86
|
+
INTEGER_ATTRIBUTES.include?(key) or
|
87
|
+
STRING_ATTRIBUTES.include?(key)
|
88
|
+
end
|
89
|
+
|
90
|
+
def authlete_model_update(hash)
|
91
|
+
return if hash.nil?
|
92
|
+
|
93
|
+
hash.each do |key, value|
|
94
|
+
key = authlete_model_convert_key(key)
|
95
|
+
|
96
|
+
if authlete_model_simple_attribute?(key)
|
97
|
+
send("#{key}=", value)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
public
|
105
|
+
|
106
|
+
# Construct an instance from the given hash.
|
107
|
+
#
|
108
|
+
# If the given argument is nil or is not a Hash, nil is returned.
|
109
|
+
# Otherwise, AuthorizationIssueRequest.new(hash) is returned.
|
110
|
+
def self.parse(hash)
|
111
|
+
if hash.nil? or (hash.kind_of?(Hash) == false)
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
|
115
|
+
return AuthorizationIssueRequest.new(hash)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Convert this object into a hash.
|
119
|
+
def to_hash
|
120
|
+
hash = {}
|
121
|
+
|
122
|
+
instance_variables.each do |var|
|
123
|
+
key = var.to_s.delete("@").to_sym
|
124
|
+
val = instance_variable_get(var)
|
125
|
+
|
126
|
+
if authlete_model_simple_attribute?(key) or val.nil?
|
127
|
+
hash[key] = val
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
hash
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
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
|
+
require 'set'
|
19
|
+
|
20
|
+
|
21
|
+
module Authlete
|
22
|
+
module Model
|
23
|
+
module Request
|
24
|
+
# == Authlete::Model::Request::AuthorizationRequest class
|
25
|
+
#
|
26
|
+
# This class represents a request to Authlete's /api/auth/authorization API.
|
27
|
+
class AuthorizationRequest < Authlete::Model::Hashable
|
28
|
+
# The OAuth 2.0 authorization request parameters. (String)
|
29
|
+
attr_accessor :parameters
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# String attributes.
|
34
|
+
STRING_ATTRIBUTES = ::Set.new([ :parameters ])
|
35
|
+
|
36
|
+
# The constructor which takes a hash that represents a JSON request to
|
37
|
+
# Authlete's /api/auth/authorization 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, AuthorizationRequest.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 AuthorizationRequest.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
|