Skip to content

Commit db13083

Browse files
authored
Merge pull request #404 from keillera/ALIS-4775
ALIS-4775: Add parameter of tokenAuthMethod to oauth application.
2 parents 719198c + b1aab8c commit db13083

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/handlers/me/applications/create/me_applications_create.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def exec_main_proc(self):
3131
'clientName': self.params['name'],
3232
'description': self.params.get('description'),
3333
'applicationType': self.params['application_type'],
34+
'tokenAuthMethod': self.__get_token_auth_method(self.params['application_type']),
3435
'clientType': self.__get_client_type_from_application_type(self.params['application_type']),
3536
'developer': self.event['requestContext']['authorizer']['claims']['cognito:username'],
3637
'redirectUris': self.params['redirect_urls'],
@@ -61,3 +62,11 @@ def __get_client_type_from_application_type(self, application_type):
6162
return 'PUBLIC'
6263
else:
6364
raise ValueError('Invalid application_type')
65+
66+
def __get_token_auth_method(self, application_type):
67+
if application_type == 'WEB':
68+
return 'CLIENT_SECRET_BASIC'
69+
elif application_type == 'NATIVE':
70+
return 'NONE'
71+
else:
72+
raise ValueError('Invalid application_type')

tests/handlers/me/applications/create/test_me_applications_create.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def tearDown(self):
2020
pass
2121

2222
@responses.activate
23-
def test_main_ok(self):
23+
def test_main_ok_type_web(self):
2424
params = {
2525
'body': {
2626
'name': 'あ' * 80,
@@ -51,6 +51,43 @@ def test_main_ok(self):
5151

5252
self.assertEqual(response['statusCode'], 200)
5353
self.assertEqual(json.loads(response['body']), {"developer": "matsumatsu20"})
54+
self.assertEqual('CONFIDENTIAL', json.loads(responses.calls[0].request.body).get('clientType'))
55+
self.assertEqual('CLIENT_SECRET_BASIC', json.loads(responses.calls[0].request.body).get('tokenAuthMethod'))
56+
57+
@responses.activate
58+
def test_main_ok_type_native(self):
59+
params = {
60+
'body': {
61+
'name': 'あ' * 80,
62+
'description': 'A' * 180,
63+
'application_type': 'NATIVE',
64+
'redirect_urls': ['http://example.com/1', 'http://example.com/2',
65+
'http://example.com/3', 'http://example.com/4', 'http://example.com/5']
66+
},
67+
'requestContext': {
68+
'authorizer': {
69+
'claims': {
70+
'cognito:username': 'user01',
71+
'phone_number_verified': 'true',
72+
'email_verified': 'true'
73+
}
74+
}
75+
}
76+
}
77+
78+
params['body'] = json.dumps(params['body'])
79+
80+
responses.add(responses.POST, settings.AUTHLETE_CLIENT_ENDPOINT + '/create',
81+
json={"developer": "matsumatsu20"}, status=200)
82+
83+
response = MeApplicationsCreate(params, {}).main()
84+
85+
logging.fatal(response)
86+
87+
self.assertEqual(response['statusCode'], 200)
88+
self.assertEqual(json.loads(response['body']), {"developer": "matsumatsu20"})
89+
self.assertEqual('PUBLIC', json.loads(responses.calls[0].request.body).get('clientType'))
90+
self.assertEqual('NONE', json.loads(responses.calls[0].request.body).get('tokenAuthMethod'))
5491

5592
@patch('requests.post', MagicMock(side_effect=requests.exceptions.RequestException()))
5693
def test_main_with_exception(self):

0 commit comments

Comments
 (0)