authlete 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlete.rb +14 -14
  3. data/lib/authlete/api.rb +115 -35
  4. data/lib/authlete/authentication-server.rb +4 -4
  5. data/lib/authlete/model/client-list.rb +127 -181
  6. data/lib/authlete/model/client.rb +444 -492
  7. data/lib/authlete/model/hashable.rb +65 -0
  8. data/lib/authlete/model/request/authentication-callback-request.rb +91 -0
  9. data/lib/authlete/model/request/authorization-fail-request.rb +107 -0
  10. data/lib/authlete/model/request/authorization-issue-request.rb +136 -0
  11. data/lib/authlete/model/request/authorization-request.rb +104 -0
  12. data/lib/authlete/model/request/developer-authentication-callback-request.rb +85 -0
  13. data/lib/authlete/model/request/introspection-request.rb +40 -0
  14. data/lib/authlete/model/request/token-fail-request.rb +104 -0
  15. data/lib/authlete/model/request/token-issue-request.rb +104 -0
  16. data/lib/authlete/model/request/token-request.rb +124 -0
  17. data/lib/authlete/model/response/authentication-callback-response.rb +54 -0
  18. data/lib/authlete/model/response/authorization-fail-response.rb +47 -0
  19. data/lib/authlete/model/response/authorization-issue-response.rb +47 -0
  20. data/lib/authlete/model/response/authorization-response.rb +146 -0
  21. data/lib/authlete/model/response/developer-authentication-callback-response.rb +56 -0
  22. data/lib/authlete/model/response/introspection-response.rb +129 -0
  23. data/lib/authlete/model/response/result.rb +45 -0
  24. data/lib/authlete/model/response/service-creatable-response.rb +51 -0
  25. data/lib/authlete/model/response/token-fail-response.rb +48 -0
  26. data/lib/authlete/model/response/token-issue-response.rb +48 -0
  27. data/lib/authlete/model/response/token-response.rb +69 -0
  28. data/lib/authlete/model/scope.rb +17 -42
  29. data/lib/authlete/model/service-list.rb +19 -74
  30. data/lib/authlete/model/service-owner.rb +16 -40
  31. data/lib/authlete/model/service.rb +20 -76
  32. data/lib/authlete/model/sns-credentials.rb +16 -41
  33. data/lib/authlete/model/tagged-value.rb +105 -135
  34. data/lib/authlete/utility.rb +29 -5
  35. data/lib/authlete/version.rb +1 -1
  36. metadata +24 -10
  37. data/lib/authlete/request/authentication-callback-request.rb +0 -90
  38. data/lib/authlete/request/developer-authentication-callback-request.rb +0 -84
  39. data/lib/authlete/response/authentication-callback-response.rb +0 -58
  40. data/lib/authlete/response/base-response.rb +0 -41
  41. data/lib/authlete/response/developer-authentication-callback-response.rb +0 -60
  42. data/lib/authlete/response/introspection-response.rb +0 -130
  43. data/lib/authlete/response/service-creatable-response.rb +0 -52
@@ -25,14 +25,23 @@ module Authlete
25
25
  end
26
26
  end
27
27
 
28
+ def extract_integer_value(hash, key)
29
+ extract_value(hash, key).to_i
30
+ end
31
+
28
32
  def extract_boolean_value(hash, key)
29
33
  value = extract_value(hash, key)
30
-
31
- return (value == true || value == 'true')
34
+ (value == true || value == 'true')
32
35
  end
33
36
 
34
- def extract_integer_value(hash, key)
35
- extract_value(hash, key).to_i
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
36
45
  end
37
46
 
38
47
  # Extract an access token (RFC 6750)
@@ -43,7 +52,22 @@ module Authlete
43
52
  return $1
44
53
  end
45
54
 
46
- return request['access_token']
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.length == 0)
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.length == 0 ? nil : elements
47
71
  end
48
72
 
49
73
  def to_rack_response_json(status_code, content)
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module Authlete
19
- VERSION = "0.3.6"
19
+ VERSION = "0.3.7"
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlete
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiko Kawasaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-07 00:00:00.000000000 Z
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -73,19 +73,33 @@ files:
73
73
  - lib/authlete/host.rb
74
74
  - lib/authlete/model/client-list.rb
75
75
  - lib/authlete/model/client.rb
76
+ - lib/authlete/model/hashable.rb
77
+ - lib/authlete/model/request/authentication-callback-request.rb
78
+ - lib/authlete/model/request/authorization-fail-request.rb
79
+ - lib/authlete/model/request/authorization-issue-request.rb
80
+ - lib/authlete/model/request/authorization-request.rb
81
+ - lib/authlete/model/request/developer-authentication-callback-request.rb
82
+ - lib/authlete/model/request/introspection-request.rb
83
+ - lib/authlete/model/request/token-fail-request.rb
84
+ - lib/authlete/model/request/token-issue-request.rb
85
+ - lib/authlete/model/request/token-request.rb
86
+ - lib/authlete/model/response/authentication-callback-response.rb
87
+ - lib/authlete/model/response/authorization-fail-response.rb
88
+ - lib/authlete/model/response/authorization-issue-response.rb
89
+ - lib/authlete/model/response/authorization-response.rb
90
+ - lib/authlete/model/response/developer-authentication-callback-response.rb
91
+ - lib/authlete/model/response/introspection-response.rb
92
+ - lib/authlete/model/response/result.rb
93
+ - lib/authlete/model/response/service-creatable-response.rb
94
+ - lib/authlete/model/response/token-fail-response.rb
95
+ - lib/authlete/model/response/token-issue-response.rb
96
+ - lib/authlete/model/response/token-response.rb
76
97
  - lib/authlete/model/scope.rb
77
98
  - lib/authlete/model/service-list.rb
78
99
  - lib/authlete/model/service-owner.rb
79
100
  - lib/authlete/model/service.rb
80
101
  - lib/authlete/model/sns-credentials.rb
81
102
  - lib/authlete/model/tagged-value.rb
82
- - lib/authlete/request/authentication-callback-request.rb
83
- - lib/authlete/request/developer-authentication-callback-request.rb
84
- - lib/authlete/response/authentication-callback-response.rb
85
- - lib/authlete/response/base-response.rb
86
- - lib/authlete/response/developer-authentication-callback-response.rb
87
- - lib/authlete/response/introspection-response.rb
88
- - lib/authlete/response/service-creatable-response.rb
89
103
  - lib/authlete/utility.rb
90
104
  - lib/authlete/version.rb
91
105
  homepage: https://www.authlete.com/
@@ -108,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
122
  version: '0'
109
123
  requirements: []
110
124
  rubyforge_project:
111
- rubygems_version: 2.2.5
125
+ rubygems_version: 2.4.5.1
112
126
  signing_key:
113
127
  specification_version: 4
114
128
  summary: A library for Authlete Web APIs
@@ -1,90 +0,0 @@
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 Request
23
- # == Authlete::Request::AuthenticationCallbackRequest class
24
- #
25
- # This class represents a request to an authentication callback endpoint.
26
- class AuthenticationCallbackRequest
27
- include Authlete::Utility
28
-
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
@@ -1,84 +0,0 @@
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 Request
23
- # == Authlete::Request::DeveloperAuthenticationCallbackRequest class
24
- #
25
- # This class represents a request to a developer authentication callback endpoint.
26
- class DeveloperAuthenticationCallbackRequest
27
- include Authlete::Utility
28
-
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
@@ -1,58 +0,0 @@
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 Response
20
- # == Authlete::Response::AuthenticationCallbackResponse class
21
- #
22
- # This class represents a response from an authentication callback endpoint.
23
- class AuthenticationCallbackResponse
24
- include Authlete::Utility
25
-
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
- # True to indicate that the authentication endpoint is mock.
36
- attr_accessor :mock
37
-
38
- # The constructor which takes a hash that represents a JSON response
39
- # from an authentication callback endpoint.
40
- def initialize(hash = {})
41
- @authenticated = extract_boolean_value(hash, :authenticated)
42
- @subject = extract_value(hash, :subject)
43
- @claims = extract_value(hash, :claims)
44
- @mock = extract_boolean_value(hash, :mock)
45
- end
46
-
47
- # Generate an array which is usable as a Rack response from this instance.
48
- def to_rack_response
49
- to_rack_response_json(200, JSON.generate(
50
- :authenticated => @authenticated,
51
- :subject => @subject,
52
- :claims => @claims,
53
- :mock => @mock
54
- ))
55
- end
56
- end
57
- end
58
- end
@@ -1,41 +0,0 @@
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 Response
20
- # == Authlete::Response::Base
21
- #
22
- # The base class of responses from Authlete Web APIs.
23
- #
24
- class BaseResponse
25
- include Authlete::Utility
26
-
27
- # The code assigned to the result of the API call.
28
- attr_accessor :result_code
29
-
30
- # The message about the result of the API call.
31
- attr_accessor :result_message
32
-
33
- # The constructor which takes a hash that represents a JSON response
34
- # from an Authlete API.
35
- def initialize(hash = {})
36
- @result_code = extract_value(hash, :resultCode)
37
- @result_message = extract_value(hash, :resultMessage)
38
- end
39
- end
40
- end
41
- end
@@ -1,60 +0,0 @@
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 Response
20
- # == Authlete::Response::DeveloperAuthenticationCallbackResponse class
21
- #
22
- # This class represents a response from a developer authentication callback endpoint.
23
- class DeveloperAuthenticationCallbackResponse
24
- include Authlete::Utility
25
-
26
- # True when the developer has been authenticated (= is a valid developer).
27
- attr_accessor :authenticated
28
-
29
- # The unique identifier of the developer.
30
- attr_accessor :subject
31
-
32
- # The display name of the developer.
33
- attr_accessor :displayName
34
- alias_method :display_name, :displayName
35
- alias_method :display_name=, :displayName=
36
-
37
- # True to indicate that the developer authentication endpoint is mock.
38
- attr_accessor :mock
39
-
40
- # The constructor which takes a hash that represents a JSON response
41
- # from a developer authentication callback endpoint.
42
- def initialize(hash = {})
43
- @authenticated = extract_boolean_value(hash, :authenticated)
44
- @subject = extract_value(hash, :subject)
45
- @displayName = extract_value(hash, :displayName)
46
- @mock = extract_boolean_value(hash, :mock)
47
- end
48
-
49
- # Generate an array which is usable as a Rack response from this instance.
50
- def to_rack_response
51
- to_rack_response_json(200, JSON.generate(
52
- :authenticated => @authenticated,
53
- :subject => @subject,
54
- :displayName => @displayName,
55
- :mock => @mock
56
- ))
57
- end
58
- end
59
- end
60
- end