Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/adal/code_request.py: 42%
24 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:05 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:05 +0000
1#------------------------------------------------------------------------------
2#
3# Copyright (c) Microsoft Corporation.
4# All rights reserved.
5#
6# This code is licensed under the MIT License.
7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files(the "Software"), to deal
10# in the Software without restriction, including without limitation the rights
11# to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12# copies of the Software, and to permit persons to whom the Software is
13# furnished to do so, subject to the following conditions :
14#
15# The above copyright notice and this permission notice shall be included in
16# all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24# THE SOFTWARE.
25#
26#------------------------------------------------------------------------------
28from . import constants
29from . import log
30from . import oauth2_client
32OAUTH2_PARAMETERS = constants.OAuth2.Parameters
34class CodeRequest(object):
35 def __init__(self, call_context, authentication_context, client_id,
36 resource):
37 self._log = log.Logger("CodeRequest", call_context['log_context'])
38 self._call_context = call_context
39 self._authentication_context = authentication_context
40 self._client_id = client_id
41 self._resource = resource
43 def _get_user_code_info(self, oauth_parameters):
44 client = self._create_oauth2_client()
45 return client.get_user_code_info(oauth_parameters)
47 def _create_oauth2_client(self):
48 return oauth2_client.OAuth2Client(
49 self._call_context,
50 self._authentication_context.authority)
52 def _create_oauth_parameters(self):
53 return {
54 OAUTH2_PARAMETERS.CLIENT_ID: self._client_id,
55 OAUTH2_PARAMETERS.RESOURCE: self._resource
56 }
58 def get_user_code_info(self, language):
59 self._log.info('Getting user code info.')
61 oauth_parameters = self._create_oauth_parameters()
62 if language:
63 oauth_parameters[OAUTH2_PARAMETERS.LANGUAGE] = language
65 return self._get_user_code_info(oauth_parameters)