authlete 0.5.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlete.rb +24 -1
  3. data/lib/authlete/api.rb +298 -146
  4. data/lib/authlete/authentication-server.rb +1 -1
  5. data/lib/authlete/exception.rb +6 -3
  6. data/lib/authlete/model/client-extension.rb +135 -135
  7. data/lib/authlete/model/client-list.rb +128 -128
  8. data/lib/authlete/model/client.rb +468 -468
  9. data/lib/authlete/model/hashable.rb +1 -1
  10. data/lib/authlete/model/pair.rb +102 -102
  11. data/lib/authlete/model/property.rb +116 -0
  12. data/lib/authlete/model/request/authentication-callback-request.rb +90 -90
  13. data/lib/authlete/model/request/authorization-fail-request.rb +107 -104
  14. data/lib/authlete/model/request/authorization-issue-request.rb +167 -133
  15. data/lib/authlete/model/request/authorization-request.rb +101 -101
  16. data/lib/authlete/model/request/client-authorization-delete-request.rb +123 -0
  17. data/lib/authlete/model/request/client-authorization-get-list-request.rb +123 -0
  18. data/lib/authlete/model/request/client-authorization-update-request.rb +118 -0
  19. data/lib/authlete/model/request/client-secret-update-request.rb +121 -0
  20. data/lib/authlete/model/request/developer-authentication-callback-request.rb +84 -84
  21. data/lib/authlete/model/request/granted-scopes-request.rb +103 -0
  22. data/lib/authlete/model/request/introspection-request.rb +117 -39
  23. data/lib/authlete/model/request/revocation-request.rb +125 -0
  24. data/lib/authlete/model/request/standard-introspection-request.rb +102 -0
  25. data/lib/authlete/model/request/token-create-request.rb +250 -0
  26. data/lib/authlete/model/request/token-fail-request.rb +104 -101
  27. data/lib/authlete/model/request/token-issue-request.rb +116 -101
  28. data/lib/authlete/model/request/token-request.rb +127 -121
  29. data/lib/authlete/model/request/token-update-request.rb +165 -0
  30. data/lib/authlete/model/request/user-info-issue-request.rb +113 -0
  31. data/lib/authlete/model/request/user-info-request.rb +102 -0
  32. data/lib/authlete/model/response/authentication-callback-response.rb +53 -53
  33. data/lib/authlete/model/response/authorization-fail-response.rb +48 -48
  34. data/lib/authlete/model/response/authorization-issue-response.rb +85 -48
  35. data/lib/authlete/model/response/authorization-response.rb +177 -164
  36. data/lib/authlete/model/response/client-authorization-get-list-response.rb +60 -0
  37. data/lib/authlete/model/response/client-secret-refresh-response.rb +48 -0
  38. data/lib/authlete/model/response/client-secret-update-response.rb +48 -0
  39. data/lib/authlete/model/response/developer-authentication-callback-response.rb +55 -55
  40. data/lib/authlete/model/response/granted-scopes-get-response.rb +63 -0
  41. data/lib/authlete/model/response/introspection-response.rb +163 -132
  42. data/lib/authlete/model/response/revocation-response.rb +49 -0
  43. data/lib/authlete/model/response/service-creatable-response.rb +50 -50
  44. data/lib/authlete/model/response/standard-introspection-response.rb +49 -0
  45. data/lib/authlete/model/response/token-create-response.rb +100 -0
  46. data/lib/authlete/model/response/token-fail-response.rb +49 -49
  47. data/lib/authlete/model/response/token-issue-response.rb +138 -49
  48. data/lib/authlete/model/response/token-response.rb +168 -70
  49. data/lib/authlete/model/response/token-update-response.rb +62 -0
  50. data/lib/authlete/model/response/user-info-issue-response.rb +47 -0
  51. data/lib/authlete/model/response/user-info-response.rb +85 -0
  52. data/lib/authlete/model/result.rb +44 -44
  53. data/lib/authlete/model/scope.rb +1 -1
  54. data/lib/authlete/model/service-list.rb +1 -1
  55. data/lib/authlete/model/service-owner.rb +1 -1
  56. data/lib/authlete/model/service.rb +4 -2
  57. data/lib/authlete/model/sns-credentials.rb +1 -1
  58. data/lib/authlete/model/tagged-value.rb +97 -97
  59. data/lib/authlete/utility.rb +1 -1
  60. data/lib/authlete/version.rb +2 -2
  61. metadata +24 -2
@@ -0,0 +1,165 @@
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
+ module Request
24
+ # == Authlete::Model::Request::TokenUpdateRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/token/update API.
27
+ class TokenUpdateRequest < Authlete::Model::Hashable
28
+ # An existing access token. (String)
29
+ attr_accessor :accessToken
30
+ alias_method :access_token, :accessToken
31
+ alias_method :access_token=, :accessToken=
32
+
33
+ #A new date at which the access token will expire in milliseconds
34
+ # since the Unix epoch (1970-01-01). If the accessTokenExpiresAt request
35
+ # parameter is not included in a request or its value is 0 (or negative),
36
+ # the expiration date of the access token is not changed. (Integer)
37
+ attr_accessor :accessTokenExpiresAt
38
+ alias_method :access_token_expires_at, :accessTokenExpiresAt
39
+ alias_method :access_token_expires_at=, :accessTokenExpiresAt=
40
+
41
+ # A new set of scopes assigned to the access token. Scopes that are not
42
+ # supported by the service and those that the client application associated
43
+ # with the access token is not allowed to request are ignored on the
44
+ # server side. If the scopes request parameter is not included in a
45
+ # request or its value is nil, the scopes of the access token are not
46
+ # changed. (String array)
47
+ attr_accessor :scopes
48
+
49
+ # A new set of properties assigned to the access token. If the properties
50
+ # request parameter is not included in a request or its value is nil,
51
+ # the properties of the access token are not changed.
52
+ # (Property array)
53
+ attr_accessor :properties
54
+
55
+ private
56
+
57
+ # Integer attributes.
58
+ INTEGER_ATTRIBUTES = ::Set.new([ :accessTokenExpiresAt ])
59
+
60
+ # String attributes.
61
+ STRING_ATTRIBUTES = ::Set.new([ :accessToken ])
62
+
63
+ # String array attributes.
64
+ STRING_ARRAY_ATTRIBUTES = ::Set.new([ :scopes ])
65
+
66
+ # Mapping from snake cases to camel cases.
67
+ SNAKE_TO_CAMEL = {
68
+ :access_token => :accessToken,
69
+ :access_expires_at => :accessTokenExpiresAt
70
+ }
71
+
72
+ # The constructor which takes a hash that represents a JSON request to
73
+ # Authlete's /api/auth/token/update API.
74
+ def initialize(hash = nil)
75
+ # Set default values to integer attributes.
76
+ INTEGER_ATTRIBUTES.each do |attr|
77
+ send("#{attr}=", 0)
78
+ end
79
+
80
+ # Set default values to string attributes.
81
+ STRING_ATTRIBUTES.each do |attr|
82
+ send("#{attr}=", nil)
83
+ end
84
+
85
+ # Set default values to string array attributes.
86
+ STRING_ARRAY_ATTRIBUTES.each do |attr|
87
+ send("#{attr}=", nil)
88
+ end
89
+
90
+ @properties = nil
91
+
92
+ # Set attribute values using the given hash.
93
+ authlete_model_update(hash)
94
+ end
95
+
96
+ def authlete_model_convert_key(key)
97
+ key = key.to_sym
98
+
99
+ # Convert snakecase to camelcase, if necessary.
100
+ if SNAKE_TO_CAMEL.has_key?(key)
101
+ key = SNAKE_TO_CAMEL[key]
102
+ end
103
+
104
+ key
105
+ end
106
+
107
+ def authlete_model_simple_attribute?(key)
108
+ INTEGER_ATTRIBUTES.include?(key) or
109
+ STRING_ATTRIBUTES.include?(key) or
110
+ STRING_ARRAY_ATTRIBUTES.include?(key)
111
+ end
112
+
113
+ def authlete_model_update(hash)
114
+ return if hash.nil?
115
+
116
+ hash.each do |key, value|
117
+ key = authlete_model_convert_key(key)
118
+
119
+ if authlete_model_simple_attribute?(key)
120
+ send("#{key}=", value)
121
+ elsif key == :properties
122
+ @properties = get_parsed_array(value) do |element|
123
+ Authlete::Model::Property.parse(element)
124
+ end
125
+ end
126
+ end
127
+
128
+ self
129
+ end
130
+
131
+ public
132
+
133
+ # Construct an instance from the given hash.
134
+ #
135
+ # If the given argument is nil or is not a Hash, nil is returned.
136
+ # Otherwise, TokenUpdateRequest.new(hash) is returned.
137
+ def self.parse(hash)
138
+ if hash.nil? or (hash.kind_of?(Hash) == false)
139
+ return nil
140
+ end
141
+
142
+ return TokenUpdateRequest.new(hash)
143
+ end
144
+
145
+ # Convert this object into a hash.
146
+ def to_hash
147
+ hash = {}
148
+
149
+ instance_variables.each do |var|
150
+ key = var.to_s.delete("@").to_sym
151
+ val = instance_variable_get(var)
152
+
153
+ if authlete_model_simple_attribute?(key) or val.nil?
154
+ hash[key] = val
155
+ elsif key == :properties
156
+ hash[key] = val.map { |element| element.to_hash }
157
+ end
158
+ end
159
+
160
+ hash
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,113 @@
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
+ module Request
24
+ # == Authlete::Model::Request::UserInfoRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/userinfo/issue API.
27
+ class UserInfoIssueRequest < Authlete::Model::Hashable
28
+ # An access token to introspect. (String)
29
+ attr_accessor :token
30
+
31
+ # Claims in JSON format.
32
+ # As for the format, see "OpenID Connect Core 1.0, 5.1. Standard Claims".
33
+ # (String)
34
+ attr_accessor :claims
35
+
36
+ # The value of the "sub" claim. If the value of this request parameter
37
+ # is not empty, it is used as the value of the "sub" claim. Otherwise,
38
+ # the value of the subject associated with the access token is used.
39
+ # (String)
40
+ attr_accessor :sub
41
+
42
+ private
43
+
44
+ # String attributes.
45
+ STRING_ATTRIBUTES = ::Set.new([ :token, :claims, :sub ])
46
+
47
+ # The constructor which takes a hash that represents a JSON request to
48
+ # Authlete's /api/auth/userinfo/issue API.
49
+ def initialize(hash = nil)
50
+ # Set default values to string attributes.
51
+ STRING_ATTRIBUTES.each do |attr|
52
+ send("#{attr}=", nil)
53
+ end
54
+
55
+ # Set attribute values using the given hash.
56
+ authlete_model_update(hash)
57
+ end
58
+
59
+ def authlete_model_convert_key(key)
60
+ key.to_sym
61
+ end
62
+
63
+ def authlete_model_simple_attribute?(key)
64
+ STRING_ATTRIBUTES.include?(key)
65
+ end
66
+
67
+ def authlete_model_update(hash)
68
+ return if hash.nil?
69
+
70
+ hash.each do |key, value|
71
+ key = authlete_model_convert_key(key)
72
+
73
+ if authlete_model_simple_attribute?(key)
74
+ send("#{key}=", value)
75
+ end
76
+ end
77
+
78
+ self
79
+ end
80
+
81
+ public
82
+
83
+ # Construct an instance from the given hash.
84
+ #
85
+ # If the given argument is nil or is not a Hash, nil is returned.
86
+ # Otherwise, UserInfoIssueRequest.new(hash) is returned.
87
+ def self.parse(hash)
88
+ if hash.nil? or (hash.kind_of?(Hash) == false)
89
+ return nil
90
+ end
91
+
92
+ return UserInfoIssueRequest.new(hash)
93
+ end
94
+
95
+ # Convert this object into a hash.
96
+ def to_hash
97
+ hash = {}
98
+
99
+ instance_variables.each do |var|
100
+ key = var.to_s.delete("@").to_sym
101
+ val = instance_variable_get(var)
102
+
103
+ if authlete_model_simple_attribute?(key) or val.nil?
104
+ hash[key] = val
105
+ end
106
+ end
107
+
108
+ hash
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,102 @@
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
+ module Request
24
+ # == Authlete::Model::Request::UserInfoRequest class
25
+ #
26
+ # This class represents a request to Authlete's /api/auth/userinfo API.
27
+ class UserInfoRequest < Authlete::Model::Hashable
28
+ # An access token to introspect. (String)
29
+ attr_accessor :token
30
+
31
+ private
32
+
33
+ # String attributes.
34
+ STRING_ATTRIBUTES = ::Set.new([ :token ])
35
+
36
+ # The constructor which takes a hash that represents a JSON request to
37
+ # Authlete's /api/auth/userinfo API.
38
+ def initialize(hash = nil)
39
+ # Set default values to string attributes.
40
+ STRING_ATTRIBUTES.each do |attr|
41
+ send("#{attr}=", nil)
42
+ end
43
+
44
+ # Set attribute values using the given hash.
45
+ authlete_model_update(hash)
46
+ end
47
+
48
+ def authlete_model_convert_key(key)
49
+ key.to_sym
50
+ end
51
+
52
+ def authlete_model_simple_attribute?(key)
53
+ STRING_ATTRIBUTES.include?(key)
54
+ end
55
+
56
+ def authlete_model_update(hash)
57
+ return if hash.nil?
58
+
59
+ hash.each do |key, value|
60
+ key = authlete_model_convert_key(key)
61
+
62
+ if authlete_model_simple_attribute?(key)
63
+ send("#{key}=", value)
64
+ end
65
+ end
66
+
67
+ self
68
+ end
69
+
70
+ public
71
+
72
+ # Construct an instance from the given hash.
73
+ #
74
+ # If the given argument is nil or is not a Hash, nil is returned.
75
+ # Otherwise, UserInfoRequest.new(hash) is returned.
76
+ def self.parse(hash)
77
+ if hash.nil? or (hash.kind_of?(Hash) == false)
78
+ return nil
79
+ end
80
+
81
+ return UserInfoRequest.new(hash)
82
+ end
83
+
84
+ # Convert this object into a hash.
85
+ def to_hash
86
+ hash = {}
87
+
88
+ instance_variables.each do |var|
89
+ key = var.to_s.delete("@").to_sym
90
+ val = instance_variable_get(var)
91
+
92
+ if authlete_model_simple_attribute?(key) or val.nil?
93
+ hash[key] = val
94
+ end
95
+ end
96
+
97
+ hash
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,54 +1,54 @@
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 Response
21
- # == Authlete::Model::Response::AuthenticationCallbackResponse class
22
- #
23
- # This class represents a response from an authentication callback endpoint.
24
- class AuthenticationCallbackResponse
25
- include Authlete::Utility
26
- # True when the end-user has been authenticated (= is a valid user).
27
- attr_accessor :authenticated
28
-
29
- # The unique identifier of the end-user.
30
- attr_accessor :subject
31
-
32
- # Pieces of information about the end-user in JSON format.
33
- attr_accessor :claims
34
-
35
- # The constructor which takes a hash that represents a JSON response
36
- # from an authentication callback endpoint.
37
- def initialize(hash = {})
38
- @authenticated = extract_boolean_value(hash, :authenticated)
39
- @subject = extract_value(hash, :subject)
40
- @claims = extract_value(hash, :claims)
41
- end
42
-
43
- # Generate an array which is usable as a Rack response from this instance.
44
- def to_rack_response
45
- to_rack_response_json(200, JSON.generate(
46
- :authenticated => @authenticated,
47
- :subject => @subject,
48
- :claims => @claims
49
- ))
50
- end
51
- end
52
- end
53
- 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 Model
20
+ module Response
21
+ # == Authlete::Model::Response::AuthenticationCallbackResponse class
22
+ #
23
+ # This class represents a response from an authentication callback endpoint.
24
+ class AuthenticationCallbackResponse
25
+ include Authlete::Utility
26
+ # True when the end-user has been authenticated (= is a valid user).
27
+ attr_accessor :authenticated
28
+
29
+ # The unique identifier of the end-user.
30
+ attr_accessor :subject
31
+
32
+ # Pieces of information about the end-user in JSON format.
33
+ attr_accessor :claims
34
+
35
+ # The constructor which takes a hash that represents a JSON response
36
+ # from an authentication callback endpoint.
37
+ def initialize(hash = {})
38
+ @authenticated = extract_boolean_value(hash, :authenticated)
39
+ @subject = extract_value(hash, :subject)
40
+ @claims = extract_value(hash, :claims)
41
+ end
42
+
43
+ # Generate an array which is usable as a Rack response from this instance.
44
+ def to_rack_response
45
+ to_rack_response_json(200, JSON.generate(
46
+ :authenticated => @authenticated,
47
+ :subject => @subject,
48
+ :claims => @claims
49
+ ))
50
+ end
51
+ end
52
+ end
53
+ end
54
54
  end