def _get_token_from_headers(self, request, refresh_token):
header = request.headers.get(self.config.authorization_header(), None)<EOL>if header is None:<EOL><INDENT>return None<EOL><DEDENT>else:<EOL><INDENT>header_prefix_key = "<STR_LIT>"<EOL>header_prefix = getattr(self.config, header_prefix_key)<EOL>if header_prefix():<EOL><INDENT>try:<EOL><INDENT>prefix, token = header.split("<STR_LIT:U+0020>")<EOL>if prefix != header_prefix():<EOL><INDENT>raise Exception<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>raise exceptions.InvalidAuthorizationHeader()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>token = header<EOL><DEDENT>if refresh_token:<EOL><INDENT>token = request.json.get(self.config.refresh_token_name())<EOL><DEDENT>return token<EOL><DEDENT>
Extract the token if present inside the headers of a request.