authlete 1.0.20 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Makefile +40 -0
- data/README.md +20 -20
- data/Rakefile +5 -0
- data/authlete.gemspec +2 -2
- data/lib/authlete.rb +28 -9
- data/lib/authlete/api.rb +153 -322
- data/lib/authlete/authentication-server.rb +230 -230
- data/lib/authlete/exception.rb +14 -15
- data/lib/authlete/model/base.rb +30 -0
- data/lib/authlete/model/client-extension.rb +17 -119
- data/lib/authlete/model/client.rb +203 -338
- data/lib/authlete/model/hashable.rb +13 -33
- data/lib/authlete/model/named-uri.rb +13 -74
- data/lib/authlete/model/pair.rb +13 -74
- data/lib/authlete/model/param-initializer.rb +45 -0
- data/lib/authlete/model/property.rb +15 -85
- data/lib/authlete/model/request/authentication-callback-request.rb +63 -55
- data/lib/authlete/model/request/authorization-fail-request.rb +14 -75
- data/lib/authlete/model/request/authorization-issue-request.rb +38 -119
- data/lib/authlete/model/request/authorization-request.rb +8 -73
- data/lib/authlete/model/request/backchannel-authentication-complete-request.rb +97 -0
- data/lib/authlete/model/request/backchannel-authentication-fail-request.rb +55 -0
- data/lib/authlete/model/request/backchannel-authentication-issue-request.rb +37 -0
- data/lib/authlete/model/request/backchannel-authentication-request.rb +63 -0
- data/lib/authlete/model/request/base.rb +26 -0
- data/lib/authlete/model/request/client-authorization-delete-request.rb +7 -93
- data/lib/authlete/model/request/client-authorization-get-list-request.rb +17 -89
- data/lib/authlete/model/request/client-authorization-update-request.rb +11 -86
- data/lib/authlete/model/request/client-registration-request.rb +49 -0
- data/lib/authlete/model/request/client-secret-update-request.rb +7 -89
- data/lib/authlete/model/request/developer-authentication-callback-request.rb +40 -43
- data/lib/authlete/model/request/device-authorization-request.rb +63 -0
- data/lib/authlete/model/request/device-complete-request.rb +99 -0
- data/lib/authlete/model/request/device-verification-request.rb +40 -0
- data/lib/authlete/model/request/granted-scopes-request.rb +8 -74
- data/lib/authlete/model/request/introspection-request.rb +24 -83
- data/lib/authlete/model/request/pushed-auth-req-request.rb +64 -0
- data/lib/authlete/model/request/revocation-request.rb +14 -88
- data/lib/authlete/model/request/standard-introspection-request.rb +8 -73
- data/lib/authlete/model/request/token-create-request.rb +52 -183
- data/lib/authlete/model/request/token-fail-request.rb +12 -74
- data/lib/authlete/model/request/token-issue-request.rb +22 -80
- data/lib/authlete/model/request/token-request.rb +44 -81
- data/lib/authlete/model/request/token-update-request.rb +35 -121
- data/lib/authlete/model/request/user-info-issue-request.rb +14 -80
- data/lib/authlete/model/request/user-info-request.rb +25 -70
- data/lib/authlete/model/response/access-token.rb +96 -0
- data/lib/authlete/model/response/authentication-callback-response.rb +24 -19
- data/lib/authlete/model/response/authorization-fail-response.rb +13 -15
- data/lib/authlete/model/response/authorization-issue-response.rb +29 -32
- data/lib/authlete/model/response/authorization-response.rb +97 -123
- data/lib/authlete/model/response/authorized-client-list-response.rb +37 -0
- data/lib/authlete/model/response/backchannel-authentication-complete-response.rb +143 -0
- data/lib/authlete/model/response/backchannel-authentication-fail-response.rb +47 -0
- data/lib/authlete/model/response/backchannel-authentication-issue-response.rb +63 -0
- data/lib/authlete/model/response/backchannel-authentication-response.rb +160 -0
- data/lib/authlete/model/response/client-list-response.rb +58 -0
- data/lib/authlete/model/response/client-registration-response.rb +50 -0
- data/lib/authlete/model/response/client-secret-refresh-response.rb +12 -12
- data/lib/authlete/model/response/client-secret-update-response.rb +12 -12
- data/lib/authlete/model/response/developer-authentication-callback-response.rb +24 -19
- data/lib/authlete/model/response/device-authorization-response.rb +134 -0
- data/lib/authlete/model/response/device-complete-response.rb +39 -0
- data/lib/authlete/model/response/device-verification-response.rb +96 -0
- data/lib/authlete/model/response/granted-scopes-get-response.rb +27 -19
- data/lib/authlete/model/response/introspection-response.rb +64 -58
- data/lib/authlete/model/response/pushed-auth-req-response.rb +59 -0
- data/lib/authlete/model/response/revocation-response.rb +12 -15
- data/lib/authlete/model/response/service-list-response.rb +54 -0
- data/lib/authlete/model/response/standard-introspection-response.rb +13 -15
- data/lib/authlete/model/response/token-create-response.rb +50 -55
- data/lib/authlete/model/response/token-fail-response.rb +14 -17
- data/lib/authlete/model/response/token-issue-response.rb +49 -62
- data/lib/authlete/model/response/token-list-response.rb +64 -0
- data/lib/authlete/model/response/token-response.rb +59 -79
- data/lib/authlete/model/response/token-update-response.rb +28 -23
- data/lib/authlete/model/response/user-info-issue-response.rb +16 -16
- data/lib/authlete/model/response/user-info-response.rb +48 -42
- data/lib/authlete/model/result.rb +14 -13
- data/lib/authlete/model/scope.rb +68 -158
- data/lib/authlete/model/service-owner.rb +32 -116
- data/lib/authlete/model/service.rb +660 -830
- data/lib/authlete/model/sns-credentials.rb +51 -124
- data/lib/authlete/model/tagged-value.rb +14 -69
- data/lib/authlete/utility.rb +70 -99
- data/lib/authlete/version.rb +3 -3
- data/test/authlete/model/request/test_authentication-callback-request.rb +100 -0
- data/test/authlete/model/request/test_authorization-fail-request.rb +67 -0
- data/test/authlete/model/request/test_authorization-issue-request.rb +94 -0
- data/test/authlete/model/request/test_authorization-request.rb +57 -0
- data/test/authlete/model/request/test_backchannel-authentication-complete-request.rb +102 -0
- data/test/authlete/model/request/test_backchannel-authentication-fail-request.rb +71 -0
- data/test/authlete/model/request/test_backchannel-authentication-issue-request.rb +57 -0
- data/test/authlete/model/request/test_backchannel-authentication-request.rb +75 -0
- data/test/authlete/model/request/test_client-authorization-delete-request.rb +57 -0
- data/test/authlete/model/request/test_client-authorization-get-list-request.rb +71 -0
- data/test/authlete/model/request/test_client-authorization-update-request.rb +63 -0
- data/test/authlete/model/request/test_client-registration-request.rb +68 -0
- data/test/authlete/model/request/test_device-authorization-request.rb +75 -0
- data/test/authlete/model/request/test_device-complete-request.rb +102 -0
- data/test/authlete/model/request/test_device-verification-request.rb +57 -0
- data/test/authlete/model/request/test_granted-scopes-request.rb +57 -0
- data/test/authlete/model/request/test_introspection-request.rb +79 -0
- data/test/authlete/model/request/test_pushed-auth-req-request.rb +75 -0
- data/test/authlete/model/request/test_revocation-request.rb +67 -0
- data/test/authlete/model/request/test_standard-introspection-request.rb +57 -0
- data/test/authlete/model/request/test_token-create-request.rb +110 -0
- data/test/authlete/model/request/test_token-fail-request.rb +63 -0
- data/test/authlete/model/request/test_token-issue-request.rb +70 -0
- data/test/authlete/model/request/test_token-request.rb +94 -0
- data/test/authlete/model/request/test_token-update-request.rb +82 -0
- data/test/authlete/model/request/test_user-info-issue-request.rb +67 -0
- data/test/authlete/model/request/test_user-info-request.rb +75 -0
- data/test/authlete/model/response/test_access-token.rb +101 -0
- data/test/authlete/model/response/test_authorization-fail-response.rb +68 -0
- data/test/authlete/model/response/test_authorization-issue-response.rb +92 -0
- data/test/authlete/model/response/test_authorization-response.rb +145 -0
- data/test/authlete/model/response/test_authorized-client-list-response.rb +83 -0
- data/test/authlete/model/response/test_backchannel-authentication-complete-response.rb +132 -0
- data/test/authlete/model/response/test_backchannel-authentication-fail-response.rb +68 -0
- data/test/authlete/model/response/test_backchannel-authentication-issue-response.rb +80 -0
- data/test/authlete/model/response/test_backchannel-authentication-response.rb +156 -0
- data/test/authlete/model/response/test_client-list-response.rb +79 -0
- data/test/authlete/model/response/test_client-secret-refresh-response.rb +68 -0
- data/test/authlete/model/response/test_client-secret-update-response.rb +68 -0
- data/test/authlete/model/response/test_device-authorization-response.rb +140 -0
- data/test/authlete/model/response/test_device-complete-response.rb +64 -0
- data/test/authlete/model/response/test_device-verification-response.rb +112 -0
- data/test/authlete/model/response/test_granted-scopes-get-response.rb +84 -0
- data/test/authlete/model/response/test_introspection-response.rb +127 -0
- data/test/authlete/model/response/test_pushed-auth-req-response.rb +76 -0
- data/test/authlete/model/response/test_revocation-response.rb +68 -0
- data/test/authlete/model/response/test_service-list-response.rb +72 -0
- data/test/authlete/model/response/test_standard-introspection-response.rb +68 -0
- data/test/authlete/model/response/test_token-create-response.rb +107 -0
- data/test/authlete/model/response/test_token-fail-response.rb +68 -0
- data/test/authlete/model/response/test_token-issue-response.rb +127 -0
- data/test/authlete/model/response/test_token-list-response.rb +84 -0
- data/test/authlete/model/response/test_token-response.rb +147 -0
- data/test/authlete/model/response/test_token-update-response.rb +87 -0
- data/test/authlete/model/response/test_user-info-issue-response.rb +68 -0
- data/test/authlete/model/response/test_user-info-response.rb +107 -0
- data/test/authlete/model/test_client-extension.rb +95 -0
- data/test/authlete/model/test_client.rb +461 -0
- data/test/authlete/model/test_named-uri.rb +85 -0
- data/test/authlete/model/test_pair.rb +85 -0
- data/test/authlete/model/test_property.rb +90 -0
- data/test/authlete/model/test_result.rb +68 -0
- data/test/authlete/model/test_scope.rb +106 -0
- data/test/authlete/model/test_service-owner.rb +80 -0
- data/test/authlete/model/test_service.rb +614 -0
- data/test/authlete/model/test_sns-credentials.rb +88 -0
- data/test/authlete/model/test_tagged-value.rb +83 -0
- data/test/authlete/test_exception.rb +70 -0
- metadata +173 -13
- data/lib/authlete/model/client-list.rb +0 -129
- data/lib/authlete/model/response/client-authorization-get-list-response.rb +0 -60
- data/lib/authlete/model/response/service-creatable-response.rb +0 -51
- data/lib/authlete/model/service-list.rb +0 -128
@@ -0,0 +1,107 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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 'authlete'
|
19
|
+
require 'json'
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
|
23
|
+
class TokenCreateResponseTest < Minitest::Test
|
24
|
+
RESULT_CODE = '<result-code>'
|
25
|
+
RESULT_MESSAGE = '<result-message>'
|
26
|
+
ACTION = 'OK'
|
27
|
+
GRANT_TYPE = 'AUTHORIZATION_CODE'
|
28
|
+
CLIENT_ID = 12345
|
29
|
+
SUBJECT = '<subject>'
|
30
|
+
SCOPES = [ 'scope0', 'scope1' ]
|
31
|
+
ACCESS_TOKEN = '<access-token>'
|
32
|
+
TOKEN_TYPE = 'Bearer'
|
33
|
+
EXPIRES_IN = 1000
|
34
|
+
EXPIRES_AT = 1000
|
35
|
+
REFRESH_TOKEN = '<refresh-token>'
|
36
|
+
PROPERTY_KEY = '<property0-key>'
|
37
|
+
PROPERTY_VALUE = '<property0-value>'
|
38
|
+
PROPERTIES = [ Authlete::Model::Property.new(key: PROPERTY_KEY, value: PROPERTY_VALUE) ]
|
39
|
+
|
40
|
+
|
41
|
+
def generate_json
|
42
|
+
return <<~JSON
|
43
|
+
{
|
44
|
+
"resultCode": "<result-code>",
|
45
|
+
"resultMessage": "<result-message>",
|
46
|
+
"action": "OK",
|
47
|
+
"grantType": "AUTHORIZATION_CODE",
|
48
|
+
"clientId": 12345,
|
49
|
+
"subject": "<subject>",
|
50
|
+
"scopes": [ "scope0", "scope1" ],
|
51
|
+
"accessToken": "<access-token>",
|
52
|
+
"tokenType": "Bearer",
|
53
|
+
"expiresIn": 1000,
|
54
|
+
"expiresAt": 1000,
|
55
|
+
"refreshToken": "<refresh-token>",
|
56
|
+
"properties": [ { "key": "<property0-key>", "value": "<property0-value>" } ]
|
57
|
+
}
|
58
|
+
JSON
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def match(obj)
|
63
|
+
assert_equal RESULT_CODE, obj.resultCode
|
64
|
+
assert_equal RESULT_MESSAGE, obj.resultMessage
|
65
|
+
assert_equal ACTION, obj.action
|
66
|
+
assert_equal GRANT_TYPE, obj.grantType
|
67
|
+
assert_equal CLIENT_ID, obj.clientId
|
68
|
+
assert_equal SUBJECT, obj.subject
|
69
|
+
assert_equal SCOPES, obj.scopes
|
70
|
+
assert_equal ACCESS_TOKEN, obj.accessToken
|
71
|
+
assert_equal TOKEN_TYPE, obj.tokenType
|
72
|
+
assert_equal EXPIRES_IN, obj.expiresIn
|
73
|
+
assert_equal EXPIRES_AT, obj.expiresAt
|
74
|
+
assert_equal REFRESH_TOKEN, obj.refreshToken
|
75
|
+
assert_equal PROPERTY_KEY, obj.properties[0].key
|
76
|
+
assert_equal PROPERTY_VALUE, obj.properties[0].value
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def test_from_json
|
81
|
+
jsn = generate_json
|
82
|
+
hsh = JSON.parse(jsn)
|
83
|
+
actual = Authlete::Model::Response::TokenCreateResponse.new(hsh)
|
84
|
+
|
85
|
+
match(actual)
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def test_setters
|
90
|
+
actual = Authlete::Model::Response::TokenCreateResponse.new
|
91
|
+
actual.result_code = RESULT_CODE
|
92
|
+
actual.result_message = RESULT_MESSAGE
|
93
|
+
actual.action = ACTION
|
94
|
+
actual.grant_type = GRANT_TYPE
|
95
|
+
actual.client_id = CLIENT_ID
|
96
|
+
actual.subject = SUBJECT
|
97
|
+
actual.scopes = SCOPES
|
98
|
+
actual.access_token = ACCESS_TOKEN
|
99
|
+
actual.token_type = TOKEN_TYPE
|
100
|
+
actual.expires_in = EXPIRES_IN
|
101
|
+
actual.expires_at = EXPIRES_AT
|
102
|
+
actual.refresh_token = REFRESH_TOKEN
|
103
|
+
actual.properties = PROPERTIES
|
104
|
+
|
105
|
+
match(actual)
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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 'authlete'
|
19
|
+
require 'json'
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
|
23
|
+
class TokenFailResponseTest < Minitest::Test
|
24
|
+
RESULT_CODE = '<result-code>'
|
25
|
+
RESULT_MESSAGE = '<result-message>'
|
26
|
+
ACTION = 'BAD_REQUEST'
|
27
|
+
RESPONSE_CONTENT = '<response-content>'
|
28
|
+
|
29
|
+
|
30
|
+
def generate_json
|
31
|
+
return <<~JSON
|
32
|
+
{
|
33
|
+
"resultCode": "<result-code>",
|
34
|
+
"resultMessage": "<result-message>",
|
35
|
+
"action": "BAD_REQUEST",
|
36
|
+
"responseContent": "<response-content>"
|
37
|
+
}
|
38
|
+
JSON
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
def match(obj)
|
43
|
+
assert_equal RESULT_CODE, obj.resultCode
|
44
|
+
assert_equal RESULT_MESSAGE, obj.resultMessage
|
45
|
+
assert_equal ACTION, obj.action
|
46
|
+
assert_equal RESPONSE_CONTENT, obj.responseContent
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_from_json
|
51
|
+
jsn = generate_json
|
52
|
+
hsh = JSON.parse(jsn)
|
53
|
+
actual = Authlete::Model::Response::TokenFailResponse.new(hsh)
|
54
|
+
|
55
|
+
match(actual)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def test_setters
|
60
|
+
actual = Authlete::Model::Response::TokenFailResponse.new
|
61
|
+
actual.result_code = RESULT_CODE
|
62
|
+
actual.result_message = RESULT_MESSAGE
|
63
|
+
actual.action = ACTION
|
64
|
+
actual.response_content = RESPONSE_CONTENT
|
65
|
+
|
66
|
+
match(actual)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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 'authlete'
|
19
|
+
require 'json'
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
|
23
|
+
class TokenIssueResponseTest < Minitest::Test
|
24
|
+
RESULT_CODE = '<result-code>'
|
25
|
+
RESULT_MESSAGE = '<result-message>'
|
26
|
+
ACTION = 'OK'
|
27
|
+
RESPONSE_CONTENT = '<response-content>'
|
28
|
+
ACCESS_TOKEN = '<access-token>'
|
29
|
+
ACCESS_TOKEN_EXPIRES_AT = 1000
|
30
|
+
ACCESS_TOKEN_DURATION = 100
|
31
|
+
REFRESH_TOKEN = '<refresh-token>'
|
32
|
+
REFRESH_TOKEN_DURATION = 200
|
33
|
+
REFRESH_TOKEN_EXPIRES_AT = 1000
|
34
|
+
CLIENT_ID = 12345
|
35
|
+
CLIENT_ID_ALIAS = '<client-id-alias>'
|
36
|
+
CLIENT_ID_ALIAS_USED = true
|
37
|
+
SUBJECT = '<subject>'
|
38
|
+
SCOPES = [ 'scope0', 'scope1' ]
|
39
|
+
PROPERTY_KEY = '<property0-key>'
|
40
|
+
PROPERTY_VALUE = '<property0-value>'
|
41
|
+
PROPERTIES = [ Authlete::Model::Property.new(key: PROPERTY_KEY, value: PROPERTY_VALUE) ]
|
42
|
+
JWT_ACCESS_TOKEN = '<jwt-access-token>'
|
43
|
+
ACCESS_TOKEN_RESOURCES = [ 'access-token-resource0', 'access-token-resource1' ]
|
44
|
+
|
45
|
+
|
46
|
+
def generate_json
|
47
|
+
return <<~JSON
|
48
|
+
{
|
49
|
+
"resultCode": "<result-code>",
|
50
|
+
"resultMessage": "<result-message>",
|
51
|
+
"action": "OK",
|
52
|
+
"responseContent": "<response-content>",
|
53
|
+
"accessToken": "<access-token>",
|
54
|
+
"accessTokenExpiresAt": 1000,
|
55
|
+
"accessTokenDuration": 100,
|
56
|
+
"refreshToken": "<refresh-token>",
|
57
|
+
"refreshTokenDuration": 200,
|
58
|
+
"refreshTokenExpiresAt": 1000,
|
59
|
+
"clientId": 12345,
|
60
|
+
"clientIdAlias": "<client-id-alias>",
|
61
|
+
"clientIdAliasUsed": true,
|
62
|
+
"subject": "<subject>",
|
63
|
+
"scopes": [ "scope0", "scope1" ],
|
64
|
+
"properties": [ { "key": "<property0-key>", "value": "<property0-value>" } ],
|
65
|
+
"jwtAccessToken": "<jwt-access-token>",
|
66
|
+
"accessTokenResources": [ "access-token-resource0", "access-token-resource1" ]
|
67
|
+
}
|
68
|
+
JSON
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def match(obj)
|
73
|
+
assert_equal RESULT_CODE, obj.resultCode
|
74
|
+
assert_equal RESULT_MESSAGE, obj.resultMessage
|
75
|
+
assert_equal ACTION, obj.action
|
76
|
+
assert_equal RESPONSE_CONTENT, obj.responseContent
|
77
|
+
assert_equal ACCESS_TOKEN, obj.accessToken
|
78
|
+
assert_equal ACCESS_TOKEN_EXPIRES_AT, obj.accessTokenExpiresAt
|
79
|
+
assert_equal ACCESS_TOKEN_DURATION, obj.accessTokenDuration
|
80
|
+
assert_equal REFRESH_TOKEN, obj.refreshToken
|
81
|
+
assert_equal REFRESH_TOKEN_EXPIRES_AT, obj.refreshTokenExpiresAt
|
82
|
+
assert_equal REFRESH_TOKEN_DURATION, obj.refreshTokenDuration
|
83
|
+
assert_equal CLIENT_ID, obj.clientId
|
84
|
+
assert_equal CLIENT_ID_ALIAS, obj.clientIdAlias
|
85
|
+
assert_equal CLIENT_ID_ALIAS_USED, obj.clientIdAliasUsed
|
86
|
+
assert_equal SUBJECT, obj.subject
|
87
|
+
assert_equal SCOPES, obj.scopes
|
88
|
+
assert_equal PROPERTY_KEY, obj.properties[0].key
|
89
|
+
assert_equal PROPERTY_VALUE, obj.properties[0].value
|
90
|
+
assert_equal JWT_ACCESS_TOKEN, obj.jwtAccessToken
|
91
|
+
assert_equal ACCESS_TOKEN_RESOURCES, obj.accessTokenResources
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def test_from_json
|
96
|
+
jsn = generate_json
|
97
|
+
hsh = JSON.parse(jsn)
|
98
|
+
actual = Authlete::Model::Response::TokenIssueResponse.new(hsh)
|
99
|
+
|
100
|
+
match(actual)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def test_setters
|
105
|
+
actual = Authlete::Model::Response::TokenIssueResponse.new
|
106
|
+
actual.result_code = RESULT_CODE
|
107
|
+
actual.result_message = RESULT_MESSAGE
|
108
|
+
actual.action = ACTION
|
109
|
+
actual.response_content = RESPONSE_CONTENT
|
110
|
+
actual.access_token = ACCESS_TOKEN
|
111
|
+
actual.access_token_expires_at = ACCESS_TOKEN_EXPIRES_AT
|
112
|
+
actual.access_token_duration = ACCESS_TOKEN_DURATION
|
113
|
+
actual.refresh_token = REFRESH_TOKEN
|
114
|
+
actual.refresh_token_expires_at = REFRESH_TOKEN_EXPIRES_AT
|
115
|
+
actual.refresh_token_duration = REFRESH_TOKEN_DURATION
|
116
|
+
actual.client_id = CLIENT_ID
|
117
|
+
actual.client_id_alias = CLIENT_ID_ALIAS
|
118
|
+
actual.client_id_alias_used = CLIENT_ID_ALIAS_USED
|
119
|
+
actual.subject = SUBJECT
|
120
|
+
actual.scopes = SCOPES
|
121
|
+
actual.properties = PROPERTIES
|
122
|
+
actual.jwt_access_token = JWT_ACCESS_TOKEN
|
123
|
+
actual.access_token_resources = ACCESS_TOKEN_RESOURCES
|
124
|
+
|
125
|
+
match(actual)
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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 'authlete'
|
19
|
+
require 'json'
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
|
23
|
+
class TokenListResponseTest < Minitest::Test
|
24
|
+
START_PARAM = 0
|
25
|
+
END_PARAM = 2
|
26
|
+
CLIENT_NAME = '<client-name>'
|
27
|
+
CLIENT_DEVELOPER = '<developer>'
|
28
|
+
CLIENT = Authlete::Model::Client.new(clientName: CLIENT_NAME, developer: CLIENT_DEVELOPER)
|
29
|
+
SUBJECT = '<subject>'
|
30
|
+
TOTAL_COUNT = 2
|
31
|
+
ACCESS_TOKEN0_HASH = '<access-token0-hash>'
|
32
|
+
ACCESS_TOKEN1_HASH = '<access-token1-hash>'
|
33
|
+
ACCESS_TOKENS = [ Authlete::Model::Response::AccessToken.new(accessTokenHash: ACCESS_TOKEN0_HASH),
|
34
|
+
Authlete::Model::Response::AccessToken.new(accessTokenHash: ACCESS_TOKEN1_HASH) ]
|
35
|
+
|
36
|
+
|
37
|
+
def generate_json
|
38
|
+
return <<~JSON
|
39
|
+
{
|
40
|
+
"start": 0,
|
41
|
+
"end": 2,
|
42
|
+
"client": { "clientName": "<client-name>", "developer": "<developer>" },
|
43
|
+
"subject": "<subject>",
|
44
|
+
"totalCount": 2,
|
45
|
+
"accessTokens": [ { "accessTokenHash": "<access-token0-hash>" },
|
46
|
+
{ "accessTokenHash": "<access-token1-hash>" } ]
|
47
|
+
}
|
48
|
+
JSON
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def match(obj)
|
53
|
+
assert_equal START_PARAM, obj.start
|
54
|
+
assert_equal END_PARAM, obj.end
|
55
|
+
assert_equal CLIENT_NAME, obj.client.clientName
|
56
|
+
assert_equal CLIENT_DEVELOPER, obj.client.developer
|
57
|
+
assert_equal SUBJECT, obj.subject
|
58
|
+
assert_equal TOTAL_COUNT, obj.totalCount
|
59
|
+
assert_equal ACCESS_TOKEN0_HASH, obj.accessTokens[0].accessTokenHash
|
60
|
+
assert_equal ACCESS_TOKEN1_HASH, obj.accessTokens[1].accessTokenHash
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def test_from_json
|
65
|
+
jsn = generate_json
|
66
|
+
hsh = JSON.parse(jsn)
|
67
|
+
actual = Authlete::Model::Response::TokenListResponse.new(hsh)
|
68
|
+
|
69
|
+
match(actual)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def test_setters
|
74
|
+
actual = Authlete::Model::Response::TokenListResponse.new
|
75
|
+
actual.start = START_PARAM
|
76
|
+
actual.end = END_PARAM
|
77
|
+
actual.client = CLIENT
|
78
|
+
actual.subject = SUBJECT
|
79
|
+
actual.total_count = TOTAL_COUNT
|
80
|
+
actual.access_tokens = ACCESS_TOKENS
|
81
|
+
|
82
|
+
match(actual)
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014-2020 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 'authlete'
|
19
|
+
require 'json'
|
20
|
+
require 'minitest/autorun'
|
21
|
+
|
22
|
+
|
23
|
+
class TokenResponseTest < Minitest::Test
|
24
|
+
RESULT_CODE = '<result-code>'
|
25
|
+
RESULT_MESSAGE = '<result-message>'
|
26
|
+
ACTION = 'OK'
|
27
|
+
RESPONSE_CONTENT = '<response-content>'
|
28
|
+
USERNAME = '<username>'
|
29
|
+
PASSWORD = '<password>'
|
30
|
+
TICKET = '<ticket>'
|
31
|
+
ACCESS_TOKEN = '<access-token>'
|
32
|
+
ACCESS_TOKEN_EXPIRES_AT = 1000
|
33
|
+
ACCESS_TOKEN_DURATION = 100
|
34
|
+
REFRESH_TOKEN = '<refresh-token>'
|
35
|
+
REFRESH_TOKEN_DURATION = 200
|
36
|
+
REFRESH_TOKEN_EXPIRES_AT = 1000
|
37
|
+
ID_TOKEN = '<id-token>'
|
38
|
+
GRANT_TYPE = 'AUTHORIZATION_CODE'
|
39
|
+
CLIENT_ID = 12345
|
40
|
+
CLIENT_ID_ALIAS = '<client-id-alias>'
|
41
|
+
CLIENT_ID_ALIAS_USED = true
|
42
|
+
SUBJECT = '<subject>'
|
43
|
+
SCOPES = [ 'scope0', 'scope1' ]
|
44
|
+
PROPERTY_KEY = '<property0-key>'
|
45
|
+
PROPERTY_VALUE = '<property0-value>'
|
46
|
+
PROPERTIES = [ Authlete::Model::Property.new(key: PROPERTY_KEY, value: PROPERTY_VALUE) ]
|
47
|
+
JWT_ACCESS_TOKEN = '<jwt-access-token>'
|
48
|
+
ACCESS_TOKEN_RESOURCES = [ 'access-token-resource0', 'access-token-resource1' ]
|
49
|
+
|
50
|
+
|
51
|
+
def generate_json
|
52
|
+
return <<~JSON
|
53
|
+
{
|
54
|
+
"resultCode": "<result-code>",
|
55
|
+
"resultMessage": "<result-message>",
|
56
|
+
"action": "OK",
|
57
|
+
"responseContent": "<response-content>",
|
58
|
+
"username": "<username>",
|
59
|
+
"password": "<password>",
|
60
|
+
"ticket": "<ticket>",
|
61
|
+
"accessToken": "<access-token>",
|
62
|
+
"accessTokenExpiresAt": 1000,
|
63
|
+
"accessTokenDuration": 100,
|
64
|
+
"refreshToken": "<refresh-token>",
|
65
|
+
"refreshTokenDuration": 200,
|
66
|
+
"refreshTokenExpiresAt": 1000,
|
67
|
+
"idToken": "<id-token>",
|
68
|
+
"grantType": "AUTHORIZATION_CODE",
|
69
|
+
"clientId": 12345,
|
70
|
+
"clientIdAlias": "<client-id-alias>",
|
71
|
+
"clientIdAliasUsed": true,
|
72
|
+
"subject": "<subject>",
|
73
|
+
"scopes": [ "scope0", "scope1" ],
|
74
|
+
"properties": [ { "key": "<property0-key>", "value": "<property0-value>" } ],
|
75
|
+
"jwtAccessToken": "<jwt-access-token>",
|
76
|
+
"accessTokenResources": [ "access-token-resource0", "access-token-resource1" ]
|
77
|
+
}
|
78
|
+
JSON
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def match(obj)
|
83
|
+
assert_equal RESULT_CODE, obj.resultCode
|
84
|
+
assert_equal RESULT_MESSAGE, obj.resultMessage
|
85
|
+
assert_equal ACTION, obj.action
|
86
|
+
assert_equal RESPONSE_CONTENT, obj.responseContent
|
87
|
+
assert_equal USERNAME, obj.username
|
88
|
+
assert_equal PASSWORD, obj.password
|
89
|
+
assert_equal TICKET, obj.ticket
|
90
|
+
assert_equal ACCESS_TOKEN, obj.accessToken
|
91
|
+
assert_equal ACCESS_TOKEN_EXPIRES_AT, obj.accessTokenExpiresAt
|
92
|
+
assert_equal ACCESS_TOKEN_DURATION, obj.accessTokenDuration
|
93
|
+
assert_equal REFRESH_TOKEN, obj.refreshToken
|
94
|
+
assert_equal REFRESH_TOKEN_EXPIRES_AT, obj.refreshTokenExpiresAt
|
95
|
+
assert_equal REFRESH_TOKEN_DURATION, obj.refreshTokenDuration
|
96
|
+
assert_equal ID_TOKEN, obj.idToken
|
97
|
+
assert_equal GRANT_TYPE, obj.grantType
|
98
|
+
assert_equal CLIENT_ID, obj.clientId
|
99
|
+
assert_equal CLIENT_ID_ALIAS, obj.clientIdAlias
|
100
|
+
assert_equal CLIENT_ID_ALIAS_USED, obj.clientIdAliasUsed
|
101
|
+
assert_equal SUBJECT, obj.subject
|
102
|
+
assert_equal SCOPES, obj.scopes
|
103
|
+
assert_equal PROPERTY_KEY, obj.properties[0].key
|
104
|
+
assert_equal PROPERTY_VALUE, obj.properties[0].value
|
105
|
+
assert_equal JWT_ACCESS_TOKEN, obj.jwtAccessToken
|
106
|
+
assert_equal ACCESS_TOKEN_RESOURCES, obj.accessTokenResources
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def test_from_json
|
111
|
+
jsn = generate_json
|
112
|
+
hsh = JSON.parse(jsn)
|
113
|
+
actual = Authlete::Model::Response::TokenResponse.new(hsh)
|
114
|
+
|
115
|
+
match(actual)
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
def test_setters
|
120
|
+
actual = Authlete::Model::Response::TokenResponse.new
|
121
|
+
actual.result_code = RESULT_CODE
|
122
|
+
actual.result_message = RESULT_MESSAGE
|
123
|
+
actual.action = ACTION
|
124
|
+
actual.response_content = RESPONSE_CONTENT
|
125
|
+
actual.username = USERNAME
|
126
|
+
actual.password = PASSWORD
|
127
|
+
actual.ticket = TICKET
|
128
|
+
actual.access_token = ACCESS_TOKEN
|
129
|
+
actual.access_token_expires_at = ACCESS_TOKEN_EXPIRES_AT
|
130
|
+
actual.access_token_duration = ACCESS_TOKEN_DURATION
|
131
|
+
actual.refresh_token = REFRESH_TOKEN
|
132
|
+
actual.refresh_token_expires_at = REFRESH_TOKEN_EXPIRES_AT
|
133
|
+
actual.refresh_token_duration = REFRESH_TOKEN_DURATION
|
134
|
+
actual.id_token = ID_TOKEN
|
135
|
+
actual.grant_type = GRANT_TYPE
|
136
|
+
actual.client_id = CLIENT_ID
|
137
|
+
actual.client_id_alias = CLIENT_ID_ALIAS
|
138
|
+
actual.client_id_alias_used = CLIENT_ID_ALIAS_USED
|
139
|
+
actual.subject = SUBJECT
|
140
|
+
actual.scopes = SCOPES
|
141
|
+
actual.properties = PROPERTIES
|
142
|
+
actual.jwt_access_token = JWT_ACCESS_TOKEN
|
143
|
+
actual.access_token_resources = ACCESS_TOKEN_RESOURCES
|
144
|
+
|
145
|
+
match(actual)
|
146
|
+
end
|
147
|
+
end
|