authlete 1.0.20 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Makefile +40 -0
  4. data/README.md +20 -20
  5. data/Rakefile +5 -0
  6. data/authlete.gemspec +2 -2
  7. data/lib/authlete.rb +28 -9
  8. data/lib/authlete/api.rb +153 -322
  9. data/lib/authlete/authentication-server.rb +230 -230
  10. data/lib/authlete/exception.rb +14 -15
  11. data/lib/authlete/model/base.rb +30 -0
  12. data/lib/authlete/model/client-extension.rb +17 -119
  13. data/lib/authlete/model/client.rb +203 -338
  14. data/lib/authlete/model/hashable.rb +13 -33
  15. data/lib/authlete/model/named-uri.rb +13 -74
  16. data/lib/authlete/model/pair.rb +13 -74
  17. data/lib/authlete/model/param-initializer.rb +45 -0
  18. data/lib/authlete/model/property.rb +15 -85
  19. data/lib/authlete/model/request/authentication-callback-request.rb +63 -55
  20. data/lib/authlete/model/request/authorization-fail-request.rb +14 -75
  21. data/lib/authlete/model/request/authorization-issue-request.rb +38 -119
  22. data/lib/authlete/model/request/authorization-request.rb +8 -73
  23. data/lib/authlete/model/request/backchannel-authentication-complete-request.rb +97 -0
  24. data/lib/authlete/model/request/backchannel-authentication-fail-request.rb +55 -0
  25. data/lib/authlete/model/request/backchannel-authentication-issue-request.rb +37 -0
  26. data/lib/authlete/model/request/backchannel-authentication-request.rb +63 -0
  27. data/lib/authlete/model/request/base.rb +26 -0
  28. data/lib/authlete/model/request/client-authorization-delete-request.rb +7 -93
  29. data/lib/authlete/model/request/client-authorization-get-list-request.rb +17 -89
  30. data/lib/authlete/model/request/client-authorization-update-request.rb +11 -86
  31. data/lib/authlete/model/request/client-registration-request.rb +49 -0
  32. data/lib/authlete/model/request/client-secret-update-request.rb +7 -89
  33. data/lib/authlete/model/request/developer-authentication-callback-request.rb +40 -43
  34. data/lib/authlete/model/request/device-authorization-request.rb +63 -0
  35. data/lib/authlete/model/request/device-complete-request.rb +99 -0
  36. data/lib/authlete/model/request/device-verification-request.rb +40 -0
  37. data/lib/authlete/model/request/granted-scopes-request.rb +8 -74
  38. data/lib/authlete/model/request/introspection-request.rb +24 -83
  39. data/lib/authlete/model/request/pushed-auth-req-request.rb +64 -0
  40. data/lib/authlete/model/request/revocation-request.rb +14 -88
  41. data/lib/authlete/model/request/standard-introspection-request.rb +8 -73
  42. data/lib/authlete/model/request/token-create-request.rb +52 -183
  43. data/lib/authlete/model/request/token-fail-request.rb +12 -74
  44. data/lib/authlete/model/request/token-issue-request.rb +22 -80
  45. data/lib/authlete/model/request/token-request.rb +44 -81
  46. data/lib/authlete/model/request/token-update-request.rb +35 -121
  47. data/lib/authlete/model/request/user-info-issue-request.rb +14 -80
  48. data/lib/authlete/model/request/user-info-request.rb +25 -70
  49. data/lib/authlete/model/response/access-token.rb +96 -0
  50. data/lib/authlete/model/response/authentication-callback-response.rb +24 -19
  51. data/lib/authlete/model/response/authorization-fail-response.rb +13 -15
  52. data/lib/authlete/model/response/authorization-issue-response.rb +29 -32
  53. data/lib/authlete/model/response/authorization-response.rb +97 -123
  54. data/lib/authlete/model/response/authorized-client-list-response.rb +37 -0
  55. data/lib/authlete/model/response/backchannel-authentication-complete-response.rb +143 -0
  56. data/lib/authlete/model/response/backchannel-authentication-fail-response.rb +47 -0
  57. data/lib/authlete/model/response/backchannel-authentication-issue-response.rb +63 -0
  58. data/lib/authlete/model/response/backchannel-authentication-response.rb +160 -0
  59. data/lib/authlete/model/response/client-list-response.rb +58 -0
  60. data/lib/authlete/model/response/client-registration-response.rb +50 -0
  61. data/lib/authlete/model/response/client-secret-refresh-response.rb +12 -12
  62. data/lib/authlete/model/response/client-secret-update-response.rb +12 -12
  63. data/lib/authlete/model/response/developer-authentication-callback-response.rb +24 -19
  64. data/lib/authlete/model/response/device-authorization-response.rb +134 -0
  65. data/lib/authlete/model/response/device-complete-response.rb +39 -0
  66. data/lib/authlete/model/response/device-verification-response.rb +96 -0
  67. data/lib/authlete/model/response/granted-scopes-get-response.rb +27 -19
  68. data/lib/authlete/model/response/introspection-response.rb +64 -58
  69. data/lib/authlete/model/response/pushed-auth-req-response.rb +59 -0
  70. data/lib/authlete/model/response/revocation-response.rb +12 -15
  71. data/lib/authlete/model/response/service-list-response.rb +54 -0
  72. data/lib/authlete/model/response/standard-introspection-response.rb +13 -15
  73. data/lib/authlete/model/response/token-create-response.rb +50 -55
  74. data/lib/authlete/model/response/token-fail-response.rb +14 -17
  75. data/lib/authlete/model/response/token-issue-response.rb +49 -62
  76. data/lib/authlete/model/response/token-list-response.rb +64 -0
  77. data/lib/authlete/model/response/token-response.rb +59 -79
  78. data/lib/authlete/model/response/token-update-response.rb +28 -23
  79. data/lib/authlete/model/response/user-info-issue-response.rb +16 -16
  80. data/lib/authlete/model/response/user-info-response.rb +48 -42
  81. data/lib/authlete/model/result.rb +14 -13
  82. data/lib/authlete/model/scope.rb +68 -158
  83. data/lib/authlete/model/service-owner.rb +32 -116
  84. data/lib/authlete/model/service.rb +660 -830
  85. data/lib/authlete/model/sns-credentials.rb +51 -124
  86. data/lib/authlete/model/tagged-value.rb +14 -69
  87. data/lib/authlete/utility.rb +70 -99
  88. data/lib/authlete/version.rb +3 -3
  89. data/test/authlete/model/request/test_authentication-callback-request.rb +100 -0
  90. data/test/authlete/model/request/test_authorization-fail-request.rb +67 -0
  91. data/test/authlete/model/request/test_authorization-issue-request.rb +94 -0
  92. data/test/authlete/model/request/test_authorization-request.rb +57 -0
  93. data/test/authlete/model/request/test_backchannel-authentication-complete-request.rb +102 -0
  94. data/test/authlete/model/request/test_backchannel-authentication-fail-request.rb +71 -0
  95. data/test/authlete/model/request/test_backchannel-authentication-issue-request.rb +57 -0
  96. data/test/authlete/model/request/test_backchannel-authentication-request.rb +75 -0
  97. data/test/authlete/model/request/test_client-authorization-delete-request.rb +57 -0
  98. data/test/authlete/model/request/test_client-authorization-get-list-request.rb +71 -0
  99. data/test/authlete/model/request/test_client-authorization-update-request.rb +63 -0
  100. data/test/authlete/model/request/test_client-registration-request.rb +68 -0
  101. data/test/authlete/model/request/test_device-authorization-request.rb +75 -0
  102. data/test/authlete/model/request/test_device-complete-request.rb +102 -0
  103. data/test/authlete/model/request/test_device-verification-request.rb +57 -0
  104. data/test/authlete/model/request/test_granted-scopes-request.rb +57 -0
  105. data/test/authlete/model/request/test_introspection-request.rb +79 -0
  106. data/test/authlete/model/request/test_pushed-auth-req-request.rb +75 -0
  107. data/test/authlete/model/request/test_revocation-request.rb +67 -0
  108. data/test/authlete/model/request/test_standard-introspection-request.rb +57 -0
  109. data/test/authlete/model/request/test_token-create-request.rb +110 -0
  110. data/test/authlete/model/request/test_token-fail-request.rb +63 -0
  111. data/test/authlete/model/request/test_token-issue-request.rb +70 -0
  112. data/test/authlete/model/request/test_token-request.rb +94 -0
  113. data/test/authlete/model/request/test_token-update-request.rb +82 -0
  114. data/test/authlete/model/request/test_user-info-issue-request.rb +67 -0
  115. data/test/authlete/model/request/test_user-info-request.rb +75 -0
  116. data/test/authlete/model/response/test_access-token.rb +101 -0
  117. data/test/authlete/model/response/test_authorization-fail-response.rb +68 -0
  118. data/test/authlete/model/response/test_authorization-issue-response.rb +92 -0
  119. data/test/authlete/model/response/test_authorization-response.rb +145 -0
  120. data/test/authlete/model/response/test_authorized-client-list-response.rb +83 -0
  121. data/test/authlete/model/response/test_backchannel-authentication-complete-response.rb +132 -0
  122. data/test/authlete/model/response/test_backchannel-authentication-fail-response.rb +68 -0
  123. data/test/authlete/model/response/test_backchannel-authentication-issue-response.rb +80 -0
  124. data/test/authlete/model/response/test_backchannel-authentication-response.rb +156 -0
  125. data/test/authlete/model/response/test_client-list-response.rb +79 -0
  126. data/test/authlete/model/response/test_client-secret-refresh-response.rb +68 -0
  127. data/test/authlete/model/response/test_client-secret-update-response.rb +68 -0
  128. data/test/authlete/model/response/test_device-authorization-response.rb +140 -0
  129. data/test/authlete/model/response/test_device-complete-response.rb +64 -0
  130. data/test/authlete/model/response/test_device-verification-response.rb +112 -0
  131. data/test/authlete/model/response/test_granted-scopes-get-response.rb +84 -0
  132. data/test/authlete/model/response/test_introspection-response.rb +127 -0
  133. data/test/authlete/model/response/test_pushed-auth-req-response.rb +76 -0
  134. data/test/authlete/model/response/test_revocation-response.rb +68 -0
  135. data/test/authlete/model/response/test_service-list-response.rb +72 -0
  136. data/test/authlete/model/response/test_standard-introspection-response.rb +68 -0
  137. data/test/authlete/model/response/test_token-create-response.rb +107 -0
  138. data/test/authlete/model/response/test_token-fail-response.rb +68 -0
  139. data/test/authlete/model/response/test_token-issue-response.rb +127 -0
  140. data/test/authlete/model/response/test_token-list-response.rb +84 -0
  141. data/test/authlete/model/response/test_token-response.rb +147 -0
  142. data/test/authlete/model/response/test_token-update-response.rb +87 -0
  143. data/test/authlete/model/response/test_user-info-issue-response.rb +68 -0
  144. data/test/authlete/model/response/test_user-info-response.rb +107 -0
  145. data/test/authlete/model/test_client-extension.rb +95 -0
  146. data/test/authlete/model/test_client.rb +461 -0
  147. data/test/authlete/model/test_named-uri.rb +85 -0
  148. data/test/authlete/model/test_pair.rb +85 -0
  149. data/test/authlete/model/test_property.rb +90 -0
  150. data/test/authlete/model/test_result.rb +68 -0
  151. data/test/authlete/model/test_scope.rb +106 -0
  152. data/test/authlete/model/test_service-owner.rb +80 -0
  153. data/test/authlete/model/test_service.rb +614 -0
  154. data/test/authlete/model/test_sns-credentials.rb +88 -0
  155. data/test/authlete/model/test_tagged-value.rb +83 -0
  156. data/test/authlete/test_exception.rb +70 -0
  157. metadata +173 -13
  158. data/lib/authlete/model/client-list.rb +0 -129
  159. data/lib/authlete/model/response/client-authorization-get-list-response.rb +0 -60
  160. data/lib/authlete/model/response/service-creatable-response.rb +0 -51
  161. data/lib/authlete/model/service-list.rb +0 -128
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2018 Authlete, Inc.
3
+ # Copyright (C) 2014-2020 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,91 +15,29 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
- require 'set'
19
-
20
-
21
18
  module Authlete
22
19
  module Model
23
20
  module Request
24
- # == Authlete::Model::Request::TokenFailRequest class
25
- #
26
- # This class represents a request to Authlete's /api/auth/token/fail API.
27
- class TokenFailRequest < Authlete::Model::Hashable
28
- # The ticket issued by Authlete's /api/auth/token API. (String)
21
+ class TokenFailRequest < Authlete::Model::Request::Base
22
+
29
23
  attr_accessor :ticket
30
24
 
31
- # The reason of the failure. (String)
32
25
  attr_accessor :reason
33
26
 
34
27
  private
35
28
 
36
- # String attributes.
37
- STRING_ATTRIBUTES = ::Set.new([ :ticket, :reason ])
38
-
39
- # The constructor which takes a hash that represents a JSON request to
40
- # Authlete's /api/auth/token/fail API.
41
- def initialize(hash = nil)
42
- # Set default values to string attributes.
43
- STRING_ATTRIBUTES.each do |attr|
44
- send("#{attr}=", nil)
45
- end
46
-
47
- # Set attribute values using the given hash.
48
- authlete_model_update(hash)
29
+ def defaults
30
+ {
31
+ ticket: nil,
32
+ reason: nil
33
+ }
49
34
  end
50
35
 
51
- def authlete_model_convert_key(key)
52
- key.to_sym
53
- end
54
-
55
- def authlete_model_simple_attribute?(key)
56
- STRING_ATTRIBUTES.include?(key)
57
- end
58
-
59
- def authlete_model_update(hash)
60
- return if hash.nil?
61
-
62
- hash.each do |key, value|
63
- key = authlete_model_convert_key(key)
64
-
65
- if authlete_model_simple_attribute?(key)
66
- send("#{key}=", value)
67
- end
68
- end
69
-
70
- self
71
- end
72
-
73
- public
74
-
75
- # Construct an instance from the given hash.
76
- #
77
- # If the given argument is nil or is not a Hash, nil is returned.
78
- # Otherwise, TokenFailRequest.new(hash) is returned.
79
- def self.parse(hash)
80
- if hash.nil? or (hash.kind_of?(Hash) == false)
81
- return nil
82
- end
83
-
84
- return TokenFailRequest.new(hash)
85
- end
86
-
87
- # Convert this object into a hash.
88
- def to_hash
89
- hash = {}
90
-
91
- instance_variables.each do |var|
92
- key = var.to_s.delete("@").to_sym
93
- val = instance_variable_get(var)
94
-
95
- if authlete_model_simple_attribute?(key) or val.nil?
96
- hash[key] = val
97
- end
98
- end
99
-
100
- hash
36
+ def set_params(hash)
37
+ @ticket = hash[:ticket]
38
+ @reason = hash[:reason]
101
39
  end
102
40
  end
103
41
  end
104
42
  end
105
- end
43
+ end
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2018 Authlete, Inc.
3
+ # Copyright (C) 2014-2020 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,103 +15,45 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
- require 'set'
19
-
20
-
21
18
  module Authlete
22
19
  module Model
23
20
  module Request
24
- # == Authlete::Model::Request::TokenIssueRequest class
25
- #
26
- # This class represents a request to Authlete's /api/auth/token/issue API.
27
- class TokenIssueRequest < Authlete::Model::Hashable
28
- # The ticket issued by Authlete's /api/auth/authorization API. (String)
21
+ class TokenIssueRequest < Authlete::Model::Request::Base
22
+ include Authlete::Utility
23
+
29
24
  attr_accessor :ticket
30
25
 
31
- # The subject (end-user) managed by the service. (String)
32
26
  attr_accessor :subject
33
27
 
34
- # Extra properties to associate with a newly created access token.
35
- # (String)
36
28
  attr_accessor :properties
37
29
 
38
30
  private
39
31
 
40
- # String attributes.
41
- STRING_ATTRIBUTES = ::Set.new([ :ticket, :subject ])
42
-
43
- # The constructor which takes a hash that represents a JSON request to
44
- # Authlete's /api/auth/token/issue API.
45
- def initialize(hash = nil)
46
- # Set default values to string attributes.
47
- STRING_ATTRIBUTES.each do |attr|
48
- send("#{attr}=", nil)
49
- end
50
-
51
- @properties = nil
52
-
53
- # Set attribute values using the given hash.
54
- authlete_model_update(hash)
55
- end
56
-
57
- def authlete_model_convert_key(key)
58
- key.to_sym
59
- end
60
-
61
- def authlete_model_simple_attribute?(key)
62
- STRING_ATTRIBUTES.include?(key)
32
+ def defaults
33
+ {
34
+ ticket: nil,
35
+ subject: nil,
36
+ properties: nil
37
+ }
63
38
  end
64
39
 
65
- def authlete_model_update(hash)
66
- return if hash.nil?
67
-
68
- hash.each do |key, value|
69
- key = authlete_model_convert_key(key)
70
-
71
- if authlete_model_simple_attribute?(key)
72
- send("#{key}=", value)
73
- elsif key == :properties
74
- @properties = get_parsed_array(value) do |element|
75
- Authlete::Model::Property.parse(element)
76
- end
77
- end
78
- end
79
-
80
- self
40
+ def set_params(hash)
41
+ @ticket = hash[:ticket]
42
+ @subject = hash[:subject]
43
+ @properties = get_parsed_array(hash[:properties]) { |e| Authlete::Model::Property.parse(e) }
81
44
  end
82
45
 
83
- public
46
+ def to_hash_value(key, var)
47
+ raw_val = instance_variable_get(var)
84
48
 
85
- # Construct an instance from the given hash.
86
- #
87
- # If the given argument is nil or is not a Hash, nil is returned.
88
- # Otherwise, TokenIssueRequest.new(hash) is returned.
89
- def self.parse(hash)
90
- if hash.nil? or (hash.kind_of?(Hash) == false)
91
- return nil
49
+ case key
50
+ when :properties
51
+ raw_val&.map { |e| e.to_hash }
52
+ else
53
+ raw_val
92
54
  end
93
-
94
- return TokenIssueRequest.new(hash)
95
- end
96
-
97
- # Convert this object into a hash.
98
- def to_hash
99
- hash = {}
100
-
101
- instance_variables.each do |var|
102
- key = var.to_s.delete("@").to_sym
103
- val = instance_variable_get(var)
104
-
105
- if authlete_model_simple_attribute?(key) or val.nil?
106
- hash[key] = val
107
- elsif key == :properties
108
- hash[key] = val.map { |element| element.to_hash }
109
- end
110
- end
111
-
112
- hash
113
55
  end
114
56
  end
115
57
  end
116
58
  end
117
- end
59
+ end
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2018 Authlete, Inc.
3
+ # Copyright (C) 2014-2020 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,114 +15,77 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
- require 'set'
19
-
20
-
21
18
  module Authlete
22
19
  module Model
23
20
  module Request
24
- # == Authlete::Model::Request::TokenRequest class
25
- #
26
- # This class represents a request to Authlete's /api/auth/token API.
27
- class TokenRequest < Authlete::Model::Hashable
28
- # OAuth 2.0 token request parameters. (String)
21
+ class TokenRequest < Authlete::Model::Request::Base
22
+ include Authlete::Utility
23
+
29
24
  attr_accessor :parameters
30
25
 
31
- # Client ID. (String)
32
26
  attr_accessor :clientId
33
27
  alias_method :client_id, :clientId
34
28
  alias_method :client_id=, :clientId=
35
29
 
36
- # Client Secret. (String)
37
30
  attr_accessor :clientSecret
38
31
  alias_method :client_secret, :clientSecret
39
32
  alias_method :client_secret=, :clientSecret=
40
33
 
41
- # Extra properties to associate with an access token. (String)
42
34
  attr_accessor :properties
43
35
 
44
- private
45
-
46
- # String attributes.
47
- STRING_ATTRIBUTES = ::Set.new([ :parameters, :clientId, :clientSecret, :properties ])
48
-
49
- # Mapping from snake cases to camel cases.
50
- SNAKE_TO_CAMEL = {
51
- :client_id => :clientId,
52
- :client_secret => :clientSecret
53
- }
54
-
55
- # The constructor which takes a hash that represents a JSON request
56
- # to Authlete's /api/auth/token API.
57
- def initialize(hash = nil)
58
- # Set default values to string attributes.
59
- STRING_ATTRIBUTES.each do |attr|
60
- send("#{attr}=", nil)
61
- end
62
-
63
- # Set attribute values using the given hash.
64
- authlete_model_update(hash)
65
- end
66
-
67
- def authlete_model_convert_key(key)
68
- key = key.to_sym
69
-
70
- # Convert snakecase to camelcase, if necessary.
71
- if SNAKE_TO_CAMEL.has_key?(key)
72
- key = SNAKE_TO_CAMEL[key]
73
- end
36
+ attr_accessor :clientCertificate
37
+ alias_method :client_certificate, :clientCertificate
38
+ alias_method :client_certificate=, :clientCertificate=
74
39
 
75
- key
76
- end
40
+ attr_accessor :clientCertificatePath
41
+ alias_method :client_certificate_path, :clientCertificatePath
42
+ alias_method :client_certificate_path=, :clientCertificatePath=
77
43
 
78
- def authlete_model_simple_attribute?(key)
79
- STRING_ATTRIBUTES.include?(key)
80
- end
44
+ attr_accessor :dpop
81
45
 
82
- def authlete_model_update(hash)
83
- return if hash.nil?
46
+ attr_accessor :htu
84
47
 
85
- hash.each do |key, value|
86
- key = authlete_model_convert_key(key)
48
+ attr_accessor :htm
87
49
 
88
- if authlete_model_simple_attribute?(key)
89
- send("#{key}=", value)
90
- end
91
- end
50
+ private
92
51
 
93
- self
52
+ def defaults
53
+ {
54
+ parameters: nil,
55
+ clientId: nil,
56
+ clientSecret: nil,
57
+ properties: nil,
58
+ clientCertificate: nil,
59
+ clientCertificatePath: nil,
60
+ dpop: nil,
61
+ htu: nil,
62
+ htm: nil
63
+ }
94
64
  end
95
65
 
96
- public
97
-
98
- # Construct an instance from the given hash.
99
- #
100
- # If the given argument is nil or is not a Hash, nil is returned.
101
- # Otherwise, TokenRequest.new(hash) is returned.
102
- def self.parse(hash)
103
- if hash.nil? or (hash.kind_of?(Hash) == false)
104
- return nil
105
- end
106
-
107
- return TokenRequest.new(hash)
66
+ def set_params(hash)
67
+ @parameters = hash[:parameters]
68
+ @clientId = hash[:clientId]
69
+ @clientSecret = hash[:clientSecret]
70
+ @properties = get_parsed_array(hash[:properties]) { |e| Authlete::Model::Property.parse(e) }
71
+ @clientCertificate = hash[:clientCertificate]
72
+ @clientCertificatePath = hash[:clientCertificatePath]
73
+ @dpop = hash[:dpop]
74
+ @htu = hash[:htu]
75
+ @htm = hash[:htm]
108
76
  end
109
77
 
110
- # Convert this object into a hash.
111
- def to_hash
112
- hash = {}
78
+ def to_hash_value(key, var)
79
+ raw_val = instance_variable_get(var)
113
80
 
114
- instance_variables.each do |var|
115
- key = var.to_s.delete("@").to_sym
116
- val = instance_variable_get(var)
117
-
118
- if authlete_model_simple_attribute?(key) or val.nil?
119
- hash[key] = val
120
- end
81
+ case key
82
+ when :properties
83
+ raw_val&.map { |e| e.to_hash }
84
+ else
85
+ raw_val
121
86
  end
122
-
123
- hash
124
87
  end
125
88
  end
126
89
  end
127
90
  end
128
- end
91
+ end
@@ -1,6 +1,6 @@
1
1
  # :nodoc:
2
2
  #
3
- # Copyright (C) 2014-2018 Authlete, Inc.
3
+ # Copyright (C) 2014-2020 Authlete, Inc.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -15,151 +15,65 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
- require 'set'
19
-
20
-
21
18
  module Authlete
22
19
  module Model
23
20
  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)
21
+ class TokenUpdateRequest < Authlete::Model::Request::Base
22
+ include Authlete::Utility
23
+
29
24
  attr_accessor :accessToken
30
25
  alias_method :access_token, :accessToken
31
26
  alias_method :access_token=, :accessToken=
32
27
 
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
28
  attr_accessor :accessTokenExpiresAt
38
29
  alias_method :access_token_expires_at, :accessTokenExpiresAt
39
30
  alias_method :access_token_expires_at=, :accessTokenExpiresAt=
40
31
 
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
32
  attr_accessor :scopes
48
33
 
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
34
  attr_accessor :properties
54
35
 
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
36
+ attr_accessor :certificateThumbprint
37
+ alias_method :certificate_thumbprint, :certificateThumbprint
38
+ alias_method :certificate_thumbprint=, :certificateThumbprint=
112
39
 
113
- def authlete_model_update(hash)
114
- return if hash.nil?
40
+ attr_accessor :dpopKeyThumbprint
41
+ alias_method :dpop_key_thumbprint, :dpopKeyThumbprint
42
+ alias_method :dpop_key_thumbprint=, :dpopKeyThumbprint=
115
43
 
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
44
+ private
127
45
 
128
- self
46
+ def defaults
47
+ {
48
+ accessToken: nil,
49
+ accessTokenExpiresAt: 0,
50
+ scopes: nil,
51
+ properties: nil,
52
+ certificateThumbprint: nil,
53
+ dpopKeyThumbprint: nil
54
+ }
129
55
  end
130
56
 
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)
57
+ def set_params(hash)
58
+ @accessToken = hash[:accessToken]
59
+ @accessTokenExpiresAt = hash[:accessTokenExpiresAt]
60
+ @scopes = hash[:scopes]
61
+ @properties = get_parsed_array(hash[:properties]) { |e| Authlete::Model::Property.parse(e) }
62
+ @certificateThumbprint = hash[:certificateThumbprint]
63
+ @dpopKeyThumbprint = hash[:dpopKeyThumbprint]
143
64
  end
144
65
 
145
- # Convert this object into a hash.
146
- def to_hash
147
- hash = {}
66
+ def to_hash_value(key, var)
67
+ raw_val = instance_variable_get(var)
148
68
 
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
69
+ case key
70
+ when :properties
71
+ raw_val&.map { |e| e.to_hash }
72
+ else
73
+ raw_val
158
74
  end
159
-
160
- hash
161
75
  end
162
76
  end
163
77
  end
164
78
  end
165
- end
79
+ end