Python get authorization token
9 Python code examples are found related to "
get authorization token".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: cr.py From jdcloud-cli with Apache License 2.0 | 6 votes |
def get_authorization_token(self): client_factory = ClientFactory('cr') client = client_factory.get(self.app) if client is None: return try: from jdcloud_sdk.services.cr.apis.GetAuthorizationTokenRequest import GetAuthorizationTokenRequest params_dict = collect_user_args(self.app) headers = collect_user_headers(self.app) req = GetAuthorizationTokenRequest(params_dict, headers) resp = client.send(req) Printer.print_result(resp) except ImportError: print('{"error":"This api is not supported, please use the newer version"}') except Exception as e: print(e)
Example 2
Source File: AuthorizationHelpers.py From Cura with GNU Lesser General Public License v3.0 | 5 votes |
def getAccessTokenUsingAuthorizationCode(self, authorization_code: str, verification_code: str) -> "AuthenticationResponse": """Request the access token from the authorization server. :param authorization_code: The authorization code from the 1st step. :param verification_code: The verification code needed for the PKCE extension. :return: An AuthenticationResponse object. """ data = { "client_id": self._settings.CLIENT_ID if self._settings.CLIENT_ID is not None else "", "redirect_uri": self._settings.CALLBACK_URL if self._settings.CALLBACK_URL is not None else "", "grant_type": "authorization_code", "code": authorization_code, "code_verifier": verification_code, "scope": self._settings.CLIENT_SCOPES if self._settings.CLIENT_SCOPES is not None else "", } try: return self.parseTokenResponse(requests.post(self._token_url, data = data)) # type: ignore except requests.exceptions.ConnectionError: return AuthenticationResponse(success=False, err_message="Unable to connect to remote server")
Example 3
Source File: ZeroFox.py From content with MIT License | 5 votes |
def get_authorization_token() -> str: """ :return: Returns the authorization token """ integration_context: Dict = demisto.getIntegrationContext() token: str = integration_context.get('token', '') if token: return token url_suffix: str = '/api-token-auth/' data_for_request: Dict = { 'username': USERNAME, 'password': PASSWORD } response_content: Dict = http_request('POST', url_suffix, data=data_for_request, continue_err=True, api_request=False) token = response_content.get('token', '') if not token: if 'res_content' in response_content: raise Exception('Failure resolving URL.') error_msg_list: List = response_content.get('non_field_errors', []) if not error_msg_list: raise Exception('Unable to log in with provided credentials.') else: raise Exception(error_msg_list[0]) demisto.setIntegrationContext({'token': token}) return token
Example 4
Source File: orcid.py From python-orcid with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_token_from_authorization_code(self, authorization_code, redirect_uri): """Like `get_token`, but using an OAuth 2 authorization code. Use this method if you run a webserver that serves as an endpoint for the redirect URI. The webserver can retrieve the authorization code from the URL that is requested by ORCID. Parameters ---------- :param redirect_uri: string The redirect uri of the institution. :param authorization_code: string The authorization code. Returns ------- :returns: dict All data of the access token. The access token itself is in the ``"access_token"`` key. """ token_dict = { "client_id": self._key, "client_secret": self._secret, "grant_type": "authorization_code", "code": authorization_code, "redirect_uri": redirect_uri, } response = requests.post(self._token_url, data=token_dict, headers={'Accept': 'application/json'}, timeout=self._timeout) response.raise_for_status() if self.do_store_raw_response: self.raw_response = response return json.loads(response.text)
Example 5
Source File: authentication.py From flask-resty with MIT License | 5 votes |
def get_token_from_authorization(self, authorization): try: scheme, token = authorization.split() except (AttributeError, ValueError) as e: raise ApiError(401, {"code": "invalid_authorization"}) from e if scheme.lower() != self.header_scheme.lower(): raise ApiError(401, {"code": "invalid_authorization.scheme"}) return token
Example 6
Source File: authz_state.py From pyop with Apache License 2.0 | 5 votes |
def get_authorization_request_for_access_token(self, access_token_value): # type: (str) -> oic.oic.message.AuthorizationRequest if access_token_value not in self.access_tokens: raise InvalidAccessToken('{} unknown'.format(access_token_value)) return AuthorizationRequest().from_dict(self.access_tokens[access_token_value][self.KEY_AUTHORIZATION_REQUEST])
Example 7
Source File: admin.py From metaflow-service with Apache License 2.0 | 4 votes |
def get_authorization_token(self, request): """ --- description: this is used exclusively for sandbox auth tags: - Auth produces: - text/plain responses: "200": description: successfully returned certs "403": description: no token for you "405": description: invalid HTTP Method "500": description: internal server error """ try: role_arn = os.environ.get("MF_USER_IAM_ROLE") region_name = os.environ.get("MF_REGION", "us-west-2") endpoint_url = os.environ.get( "MF_STS_ENDPOINT", "https://sts.us-west-2.amazonaws.com" ) config = Config(connect_timeout=1, read_timeout=1) sts_connection = boto3.client( "sts", config=config, region_name=region_name, endpoint_url=endpoint_url ) assumed_role = sts_connection.assume_role( RoleArn=role_arn, RoleSessionName="acct_role" ) credentials = {} credentials["aws_access_key_id"] = assumed_role["Credentials"][ "AccessKeyId" ] credentials["aws_secret_access_key"] = assumed_role["Credentials"][ "SecretAccessKey" ] credentials["aws_session_token"] = assumed_role["Credentials"][ "SessionToken" ] return web.Response(status=200, body=json.dumps(credentials)) except Exception as ex: body = {"err_msg": str(ex), "traceback": get_traceback_str()} return web.Response(status=500, body=json.dumps(body))
Example 8
Source File: ecr.py From pyboto3 with MIT License | 4 votes |
def get_authorization_token(registryIds=None): """ Retrieves an authorization token. An authorization token represents your IAM authentication credentials and can be used to access any Amazon ECR registry that your IAM principal has access to. The authorization token is valid for 12 hours. The authorizationToken returned is a base64 encoded string that can be decoded and used in a docker login command to authenticate to a registry. The AWS CLI offers an get-login-password command that simplifies the login process. For more information, see Registry Authentication in the Amazon Elastic Container Registry User Guide . See also: AWS API Documentation Exceptions :example: response = client.get_authorization_token( registryIds=[ 'string', ] ) :type registryIds: list :param registryIds: A list of AWS account IDs that are associated with the registries for which to get AuthorizationData objects. If you do not specify a registry, the default registry is assumed.\n\n(string) --\n\n :rtype: dict ReturnsResponse Syntax{ 'authorizationData': [ { 'authorizationToken': 'string', 'expiresAt': datetime(2015, 1, 1), 'proxyEndpoint': 'string' }, ] } Response Structure (dict) -- authorizationData (list) --A list of authorization token data objects that correspond to the registryIds values in the request. (dict) --An object representing authorization data for an Amazon ECR registry. authorizationToken (string) --A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the string is decoded, it is presented in the format user:password for private registry authentication using docker login . expiresAt (datetime) --The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are valid for 12 hours. proxyEndpoint (string) --The registry URL to use for this authorization token in a docker login command. The Amazon ECR registry URL format is https://aws_account_id.dkr.ecr.region.amazonaws.com . For example, https://012345678910.dkr.ecr.us-east-1.amazonaws.com .. Exceptions ECR.Client.exceptions.ServerException ECR.Client.exceptions.InvalidParameterException :return: { 'authorizationData': [ { 'authorizationToken': 'string', 'expiresAt': datetime(2015, 1, 1), 'proxyEndpoint': 'string' }, ] } :returns: ECR.Client.exceptions.ServerException ECR.Client.exceptions.InvalidParameterException """ pass
Example 9
Source File: client.py From boto3_type_annotations with MIT License | 4 votes |
def get_authorization_token(self, registryIds: List = None) -> Dict: """ Retrieves a token that is valid for a specified registry for 12 hours. This command allows you to use the ``docker`` CLI to push and pull images with Amazon ECR. If you do not specify a registry, the default registry is assumed. The ``authorizationToken`` returned for each registry specified is a base64 encoded string that can be decoded and used in a ``docker login`` command to authenticate to a registry. The AWS CLI offers an ``aws ecr get-login`` command that simplifies the login process. See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/ecr-2015-09-21/GetAuthorizationToken>`_ **Request Syntax** :: response = client.get_authorization_token( registryIds=[ 'string', ] ) **Response Syntax** :: { 'authorizationData': [ { 'authorizationToken': 'string', 'expiresAt': datetime(2015, 1, 1), 'proxyEndpoint': 'string' }, ] } **Response Structure** - *(dict) --* - **authorizationData** *(list) --* A list of authorization token data objects that correspond to the ``registryIds`` values in the request. - *(dict) --* An object representing authorization data for an Amazon ECR registry. - **authorizationToken** *(string) --* A base64-encoded string that contains authorization data for the specified Amazon ECR registry. When the string is decoded, it is presented in the format ``user:password`` for private registry authentication using ``docker login`` . - **expiresAt** *(datetime) --* The Unix time in seconds and milliseconds when the authorization token expires. Authorization tokens are valid for 12 hours. - **proxyEndpoint** *(string) --* The registry URL to use for this authorization token in a ``docker login`` command. The Amazon ECR registry URL format is ``https://aws_account_id.dkr.ecr.region.amazonaws.com`` . For example, ``https://012345678910.dkr.ecr.us-east-1.amazonaws.com`` .. :type registryIds: list :param registryIds: A list of AWS account IDs that are associated with the registries for which to get authorization tokens. If you do not specify a registry, the default registry is assumed. - *(string) --* :rtype: dict :returns: """ pass