Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed-BoldOblique.ttf +3 -0
- evalkit_tf446/lib/python3.10/site-packages/executing/__init__.py +25 -0
- evalkit_tf446/lib/python3.10/site-packages/executing/_position_node_finder.py +927 -0
- evalkit_tf446/lib/python3.10/site-packages/ninja-1.11.1.1.dist-info/LICENSE_Apache_20 +191 -0
- evalkit_tf446/lib/python3.10/site-packages/ninja-1.11.1.1.dist-info/RECORD +20 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/errors.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/parameters.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/request_validator.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/tokens.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/utils.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__init__.py +14 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/backend_application.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/base.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/legacy_application.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/mobile_application.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/service_application.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/web_application.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/backend_application.py +74 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/base.py +604 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/legacy_application.py +84 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/mobile_application.py +174 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/service_application.py +189 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py +222 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/authorization.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/base.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/introspect.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/metadata.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/pre_configured.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/resource.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/revocation.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/token.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/authorization.py +114 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/introspect.py +120 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/pre_configured.py +216 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/revocation.py +126 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__init__.py +11 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/authorization_code.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/base.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/client_credentials.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/implicit.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/refresh_token.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/resource_owner_password_credentials.cpython-310.pyc +0 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py +548 -0
- evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/base.py +268 -0
.gitattributes
CHANGED
|
@@ -2633,3 +2633,4 @@ evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSans.ttf filter=lf
|
|
| 2633 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSans-ExtraLight.ttf filter=lfs diff=lfs merge=lfs -text
|
| 2634 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed.ttf filter=lfs diff=lfs merge=lfs -text
|
| 2635 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed-Oblique.ttf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 2633 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSans-ExtraLight.ttf filter=lfs diff=lfs merge=lfs -text
|
| 2634 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed.ttf filter=lfs diff=lfs merge=lfs -text
|
| 2635 |
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed-Oblique.ttf filter=lfs diff=lfs merge=lfs -text
|
| 2636 |
+
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed-BoldOblique.ttf filter=lfs diff=lfs merge=lfs -text
|
evalkit_tf446/lib/python3.10/site-packages/cv2/qt/fonts/DejaVuSansCondensed-BoldOblique.ttf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6657693a18ecefee2667d9d0ecb1abb68524d627999bd8365039c19e04b42381
|
| 3 |
+
size 580168
|
evalkit_tf446/lib/python3.10/site-packages/executing/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Get information about what a frame is currently doing. Typical usage:
|
| 3 |
+
|
| 4 |
+
import executing
|
| 5 |
+
|
| 6 |
+
node = executing.Source.executing(frame).node
|
| 7 |
+
# node will be an AST node or None
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from collections import namedtuple
|
| 11 |
+
_VersionInfo = namedtuple('_VersionInfo', ('major', 'minor', 'micro'))
|
| 12 |
+
from .executing import Source, Executing, only, NotOneValueFound, cache, future_flags
|
| 13 |
+
try:
|
| 14 |
+
from .version import __version__ # type: ignore[import]
|
| 15 |
+
if "dev" in __version__:
|
| 16 |
+
raise ValueError
|
| 17 |
+
except Exception:
|
| 18 |
+
# version.py is auto-generated with the git tag when building
|
| 19 |
+
__version__ = "???"
|
| 20 |
+
__version_info__ = _VersionInfo(-1, -1, -1)
|
| 21 |
+
else:
|
| 22 |
+
__version_info__ = _VersionInfo(*map(int, __version__.split('.')))
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
__all__ = ["Source"]
|
evalkit_tf446/lib/python3.10/site-packages/executing/_position_node_finder.py
ADDED
|
@@ -0,0 +1,927 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
import sys
|
| 3 |
+
import dis
|
| 4 |
+
from types import CodeType, FrameType
|
| 5 |
+
from typing import Any, Callable, Iterator, Optional, Sequence, Set, Tuple, Type, Union, cast
|
| 6 |
+
from .executing import EnhancedAST, NotOneValueFound, Source, only, function_node_types, assert_
|
| 7 |
+
from ._exceptions import KnownIssue, VerifierFailure
|
| 8 |
+
|
| 9 |
+
from functools import lru_cache
|
| 10 |
+
|
| 11 |
+
# the code in this module can use all python>=3.11 features
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def parents(node: EnhancedAST) -> Iterator[EnhancedAST]:
|
| 15 |
+
while True:
|
| 16 |
+
if hasattr(node, "parent"):
|
| 17 |
+
node = node.parent
|
| 18 |
+
yield node
|
| 19 |
+
else:
|
| 20 |
+
break # pragma: no mutate
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def node_and_parents(node: EnhancedAST) -> Iterator[EnhancedAST]:
|
| 24 |
+
yield node
|
| 25 |
+
yield from parents(node)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def mangled_name(node: EnhancedAST) -> str:
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
Parameters:
|
| 32 |
+
node: the node which should be mangled
|
| 33 |
+
name: the name of the node
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
The mangled name of `node`
|
| 37 |
+
"""
|
| 38 |
+
if isinstance(node, ast.Attribute):
|
| 39 |
+
name = node.attr
|
| 40 |
+
elif isinstance(node, ast.Name):
|
| 41 |
+
name = node.id
|
| 42 |
+
elif isinstance(node, (ast.alias)):
|
| 43 |
+
name = node.asname or node.name.split(".")[0]
|
| 44 |
+
elif isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef)):
|
| 45 |
+
name = node.name
|
| 46 |
+
elif isinstance(node, ast.ExceptHandler):
|
| 47 |
+
assert node.name
|
| 48 |
+
name = node.name
|
| 49 |
+
elif sys.version_info >= (3,12) and isinstance(node,ast.TypeVar):
|
| 50 |
+
name=node.name
|
| 51 |
+
else:
|
| 52 |
+
raise TypeError("no node to mangle for type "+repr(type(node)))
|
| 53 |
+
|
| 54 |
+
if name.startswith("__") and not name.endswith("__"):
|
| 55 |
+
|
| 56 |
+
parent,child=node.parent,node
|
| 57 |
+
|
| 58 |
+
while not (isinstance(parent,ast.ClassDef) and child not in parent.bases):
|
| 59 |
+
if not hasattr(parent,"parent"):
|
| 60 |
+
break # pragma: no mutate
|
| 61 |
+
|
| 62 |
+
parent,child=parent.parent,parent
|
| 63 |
+
else:
|
| 64 |
+
class_name=parent.name.lstrip("_")
|
| 65 |
+
if class_name!="":
|
| 66 |
+
return "_" + class_name + name
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
return name
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@lru_cache(128) # pragma: no mutate
|
| 74 |
+
def get_instructions(code: CodeType) -> list[dis.Instruction]:
|
| 75 |
+
return list(dis.get_instructions(code))
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
types_cmp_issue_fix = (
|
| 79 |
+
ast.IfExp,
|
| 80 |
+
ast.If,
|
| 81 |
+
ast.Assert,
|
| 82 |
+
ast.While,
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
types_cmp_issue = types_cmp_issue_fix + (
|
| 86 |
+
ast.ListComp,
|
| 87 |
+
ast.SetComp,
|
| 88 |
+
ast.DictComp,
|
| 89 |
+
ast.GeneratorExp,
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
op_type_map = {
|
| 93 |
+
"**": ast.Pow,
|
| 94 |
+
"*": ast.Mult,
|
| 95 |
+
"@": ast.MatMult,
|
| 96 |
+
"//": ast.FloorDiv,
|
| 97 |
+
"/": ast.Div,
|
| 98 |
+
"%": ast.Mod,
|
| 99 |
+
"+": ast.Add,
|
| 100 |
+
"-": ast.Sub,
|
| 101 |
+
"<<": ast.LShift,
|
| 102 |
+
">>": ast.RShift,
|
| 103 |
+
"&": ast.BitAnd,
|
| 104 |
+
"^": ast.BitXor,
|
| 105 |
+
"|": ast.BitOr,
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class PositionNodeFinder(object):
|
| 110 |
+
"""
|
| 111 |
+
Mapping bytecode to ast-node based on the source positions, which where introduced in pyhon 3.11.
|
| 112 |
+
In general every ast-node can be exactly referenced by its begin/end line/col_offset, which is stored in the bytecode.
|
| 113 |
+
There are only some exceptions for methods and attributes.
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
def __init__(self, frame: FrameType, stmts: Set[EnhancedAST], tree: ast.Module, lasti: int, source: Source):
|
| 117 |
+
self.bc_dict={bc.offset:bc for bc in get_instructions(frame.f_code) }
|
| 118 |
+
|
| 119 |
+
self.source = source
|
| 120 |
+
self.decorator: Optional[EnhancedAST] = None
|
| 121 |
+
|
| 122 |
+
# work around for https://github.com/python/cpython/issues/96970
|
| 123 |
+
while self.opname(lasti) == "CACHE":
|
| 124 |
+
lasti -= 2
|
| 125 |
+
|
| 126 |
+
try:
|
| 127 |
+
# try to map with all match_positions
|
| 128 |
+
self.result = self.find_node(lasti)
|
| 129 |
+
except NotOneValueFound:
|
| 130 |
+
typ: tuple[Type]
|
| 131 |
+
# LOAD_METHOD could load "".join for long "..."%(...) BinOps
|
| 132 |
+
# this can only be associated by using all positions
|
| 133 |
+
if self.opname(lasti) in (
|
| 134 |
+
"LOAD_METHOD",
|
| 135 |
+
"LOAD_ATTR",
|
| 136 |
+
"STORE_ATTR",
|
| 137 |
+
"DELETE_ATTR",
|
| 138 |
+
):
|
| 139 |
+
# lineno and col_offset of LOAD_METHOD and *_ATTR instructions get set to the beginning of
|
| 140 |
+
# the attribute by the python compiler to improved error messages (PEP-657)
|
| 141 |
+
# we ignore here the start position and try to find the ast-node just by end position and expected node type
|
| 142 |
+
# This is save, because there can only be one attribute ending at a specific point in the source code.
|
| 143 |
+
typ = (ast.Attribute,)
|
| 144 |
+
elif self.opname(lasti) in ("CALL", "CALL_KW"):
|
| 145 |
+
# A CALL instruction can be a method call, in which case the lineno and col_offset gets changed by the compiler.
|
| 146 |
+
# Therefore we ignoring here this attributes and searchnig for a Call-node only by end_col_offset and end_lineno.
|
| 147 |
+
# This is save, because there can only be one method ending at a specific point in the source code.
|
| 148 |
+
# One closing ) only belongs to one method.
|
| 149 |
+
typ = (ast.Call,)
|
| 150 |
+
else:
|
| 151 |
+
raise
|
| 152 |
+
|
| 153 |
+
self.result = self.find_node(
|
| 154 |
+
lasti,
|
| 155 |
+
match_positions=("end_col_offset", "end_lineno"),
|
| 156 |
+
typ=typ,
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
instruction = self.instruction(lasti)
|
| 160 |
+
assert instruction is not None
|
| 161 |
+
|
| 162 |
+
self.result = self.fix_result(self.result, instruction)
|
| 163 |
+
|
| 164 |
+
self.known_issues(self.result, instruction)
|
| 165 |
+
|
| 166 |
+
self.test_for_decorator(self.result, lasti)
|
| 167 |
+
|
| 168 |
+
# verify
|
| 169 |
+
if self.decorator is None:
|
| 170 |
+
self.verify(self.result, instruction)
|
| 171 |
+
else:
|
| 172 |
+
assert_(self.decorator in self.result.decorator_list)
|
| 173 |
+
|
| 174 |
+
def test_for_decorator(self, node: EnhancedAST, index: int) -> None:
|
| 175 |
+
if (
|
| 176 |
+
isinstance(node.parent, (ast.ClassDef, function_node_types))
|
| 177 |
+
and node in node.parent.decorator_list # type: ignore[attr-defined]
|
| 178 |
+
):
|
| 179 |
+
node_func = node.parent
|
| 180 |
+
|
| 181 |
+
while True:
|
| 182 |
+
# the generated bytecode looks like follow:
|
| 183 |
+
|
| 184 |
+
# index opname
|
| 185 |
+
# ------------------
|
| 186 |
+
# index-4 PRECALL (only in 3.11)
|
| 187 |
+
# index-2 CACHE
|
| 188 |
+
# index CALL <- the call instruction
|
| 189 |
+
# ... CACHE some CACHE instructions
|
| 190 |
+
|
| 191 |
+
# maybe multiple other bytecode blocks for other decorators
|
| 192 |
+
# index-4 PRECALL (only in 3.11)
|
| 193 |
+
# index-2 CACHE
|
| 194 |
+
# index CALL <- index of the next loop
|
| 195 |
+
# ... CACHE some CACHE instructions
|
| 196 |
+
|
| 197 |
+
# index+x STORE_* the ast-node of this instruction points to the decorated thing
|
| 198 |
+
|
| 199 |
+
if not (
|
| 200 |
+
(self.opname(index - 4) == "PRECALL" or sys.version_info >= (3, 12))
|
| 201 |
+
and self.opname(index) == "CALL"
|
| 202 |
+
): # pragma: no mutate
|
| 203 |
+
break # pragma: no mutate
|
| 204 |
+
|
| 205 |
+
index += 2
|
| 206 |
+
|
| 207 |
+
while self.opname(index) in ("CACHE", "EXTENDED_ARG"):
|
| 208 |
+
index += 2
|
| 209 |
+
|
| 210 |
+
if (
|
| 211 |
+
self.opname(index).startswith("STORE_")
|
| 212 |
+
and self.find_node(index) == node_func
|
| 213 |
+
):
|
| 214 |
+
self.result = node_func
|
| 215 |
+
self.decorator = node
|
| 216 |
+
return
|
| 217 |
+
|
| 218 |
+
if sys.version_info < (3, 12):
|
| 219 |
+
index += 4
|
| 220 |
+
|
| 221 |
+
def fix_result(
|
| 222 |
+
self, node: EnhancedAST, instruction: dis.Instruction
|
| 223 |
+
) -> EnhancedAST:
|
| 224 |
+
if (
|
| 225 |
+
sys.version_info >= (3, 12, 5)
|
| 226 |
+
and instruction.opname in ("GET_ITER", "FOR_ITER")
|
| 227 |
+
and isinstance(node.parent, ast.For)
|
| 228 |
+
and node is node.parent.iter
|
| 229 |
+
):
|
| 230 |
+
# node positions have changed in 3.12.5
|
| 231 |
+
# https://github.com/python/cpython/issues/93691
|
| 232 |
+
# `for` calls __iter__ and __next__ during execution, the calling
|
| 233 |
+
# expression of these calls was the ast.For node since cpython 3.11 (see test_iter).
|
| 234 |
+
# cpython 3.12.5 changed this to the `iter` node of the loop, to make tracebacks easier to read.
|
| 235 |
+
# This keeps backward compatibility with older executing versions.
|
| 236 |
+
|
| 237 |
+
# there are also cases like:
|
| 238 |
+
#
|
| 239 |
+
# for a in iter(l): pass
|
| 240 |
+
#
|
| 241 |
+
# where `iter(l)` would be otherwise the resulting node for the `iter()` call and the __iter__ call of the for implementation.
|
| 242 |
+
# keeping the old behaviour makes it possible to distinguish both cases.
|
| 243 |
+
|
| 244 |
+
return node.parent
|
| 245 |
+
return node
|
| 246 |
+
|
| 247 |
+
def known_issues(self, node: EnhancedAST, instruction: dis.Instruction) -> None:
|
| 248 |
+
if instruction.opname in ("COMPARE_OP", "IS_OP", "CONTAINS_OP") and isinstance(
|
| 249 |
+
node, types_cmp_issue
|
| 250 |
+
):
|
| 251 |
+
if isinstance(node, types_cmp_issue_fix):
|
| 252 |
+
# this is a workaround for https://github.com/python/cpython/issues/95921
|
| 253 |
+
# we can fix cases with only on comparison inside the test condition
|
| 254 |
+
#
|
| 255 |
+
# we can not fix cases like:
|
| 256 |
+
# if a<b<c and d<e<f: pass
|
| 257 |
+
# if (a<b<c)!=d!=e: pass
|
| 258 |
+
# because we don't know which comparison caused the problem
|
| 259 |
+
|
| 260 |
+
comparisons = [
|
| 261 |
+
n
|
| 262 |
+
for n in ast.walk(node.test) # type: ignore[attr-defined]
|
| 263 |
+
if isinstance(n, ast.Compare) and len(n.ops) > 1
|
| 264 |
+
]
|
| 265 |
+
|
| 266 |
+
assert_(comparisons, "expected at least one comparison")
|
| 267 |
+
|
| 268 |
+
if len(comparisons) == 1:
|
| 269 |
+
node = self.result = cast(EnhancedAST, comparisons[0])
|
| 270 |
+
else:
|
| 271 |
+
raise KnownIssue(
|
| 272 |
+
"multiple chain comparison inside %s can not be fixed" % (node)
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
else:
|
| 276 |
+
# Comprehension and generators get not fixed for now.
|
| 277 |
+
raise KnownIssue("chain comparison inside %s can not be fixed" % (node))
|
| 278 |
+
|
| 279 |
+
if (
|
| 280 |
+
sys.version_info[:3] == (3, 11, 1)
|
| 281 |
+
and isinstance(node, ast.Compare)
|
| 282 |
+
and instruction.opname == "CALL"
|
| 283 |
+
and any(isinstance(n, ast.Assert) for n in node_and_parents(node))
|
| 284 |
+
):
|
| 285 |
+
raise KnownIssue(
|
| 286 |
+
"known bug in 3.11.1 https://github.com/python/cpython/issues/95921"
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
if isinstance(node, ast.Assert):
|
| 290 |
+
# pytest assigns the position of the assertion to all expressions of the rewritten assertion.
|
| 291 |
+
# All the rewritten expressions get mapped to ast.Assert, which is the wrong ast-node.
|
| 292 |
+
# We don't report this wrong result.
|
| 293 |
+
raise KnownIssue("assert")
|
| 294 |
+
|
| 295 |
+
if any(isinstance(n, ast.pattern) for n in node_and_parents(node)):
|
| 296 |
+
# TODO: investigate
|
| 297 |
+
raise KnownIssue("pattern matching ranges seems to be wrong")
|
| 298 |
+
|
| 299 |
+
if (
|
| 300 |
+
sys.version_info >= (3, 12)
|
| 301 |
+
and isinstance(node, ast.Call)
|
| 302 |
+
and isinstance(node.func, ast.Name)
|
| 303 |
+
and node.func.id == "super"
|
| 304 |
+
):
|
| 305 |
+
# super is optimized to some instructions which do not map nicely to a Call
|
| 306 |
+
|
| 307 |
+
# find the enclosing function
|
| 308 |
+
func = node.parent
|
| 309 |
+
while hasattr(func, "parent") and not isinstance(
|
| 310 |
+
func, (ast.AsyncFunctionDef, ast.FunctionDef)
|
| 311 |
+
):
|
| 312 |
+
|
| 313 |
+
func = func.parent
|
| 314 |
+
|
| 315 |
+
# get the first function argument (self/cls)
|
| 316 |
+
first_arg = None
|
| 317 |
+
|
| 318 |
+
if hasattr(func, "args"):
|
| 319 |
+
args = [*func.args.posonlyargs, *func.args.args]
|
| 320 |
+
if args:
|
| 321 |
+
first_arg = args[0].arg
|
| 322 |
+
|
| 323 |
+
if (instruction.opname, instruction.argval) in [
|
| 324 |
+
("LOAD_DEREF", "__class__"),
|
| 325 |
+
("LOAD_FAST", first_arg),
|
| 326 |
+
("LOAD_DEREF", first_arg),
|
| 327 |
+
]:
|
| 328 |
+
raise KnownIssue("super optimization")
|
| 329 |
+
|
| 330 |
+
if self.is_except_cleanup(instruction, node):
|
| 331 |
+
raise KnownIssue("exeption cleanup does not belong to the last node in a except block")
|
| 332 |
+
|
| 333 |
+
if instruction.opname == "STORE_NAME" and instruction.argval == "__classcell__":
|
| 334 |
+
# handle stores to __classcell__ as KnownIssue,
|
| 335 |
+
# because they get complicated if they are used in `if` or `for` loops
|
| 336 |
+
# example:
|
| 337 |
+
#
|
| 338 |
+
# class X:
|
| 339 |
+
# # ... something
|
| 340 |
+
# if some_condition:
|
| 341 |
+
# def method(self):
|
| 342 |
+
# super()
|
| 343 |
+
#
|
| 344 |
+
# The `STORE_NAME` instruction gets mapped to the `ast.If` node,
|
| 345 |
+
# because it is the last element in the class.
|
| 346 |
+
# This last element could be anything and gets dificult to verify.
|
| 347 |
+
|
| 348 |
+
raise KnownIssue("store __classcell__")
|
| 349 |
+
|
| 350 |
+
if (
|
| 351 |
+
instruction.opname == "CALL"
|
| 352 |
+
and not isinstance(node,ast.Call)
|
| 353 |
+
and any(isinstance(p, ast.Assert) for p in parents(node))
|
| 354 |
+
and sys.version_info >= (3, 11, 2)
|
| 355 |
+
):
|
| 356 |
+
raise KnownIssue("exception generation maps to condition")
|
| 357 |
+
|
| 358 |
+
if sys.version_info >= (3, 13):
|
| 359 |
+
if instruction.opname in (
|
| 360 |
+
"STORE_FAST_STORE_FAST",
|
| 361 |
+
"STORE_FAST_LOAD_FAST",
|
| 362 |
+
"LOAD_FAST_LOAD_FAST",
|
| 363 |
+
):
|
| 364 |
+
raise KnownIssue(f"can not map {instruction.opname} to two ast nodes")
|
| 365 |
+
|
| 366 |
+
if instruction.opname == "LOAD_FAST" and instruction.argval == "__class__":
|
| 367 |
+
# example:
|
| 368 |
+
# class T:
|
| 369 |
+
# def a():
|
| 370 |
+
# super()
|
| 371 |
+
# some_node # <- there is a LOAD_FAST for this node because we use super()
|
| 372 |
+
|
| 373 |
+
raise KnownIssue(
|
| 374 |
+
f"loading of __class__ is accociated with a random node at the end of a class if you use super()"
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
if (
|
| 378 |
+
instruction.opname == "COMPARE_OP"
|
| 379 |
+
and isinstance(node, ast.UnaryOp)
|
| 380 |
+
and isinstance(node.operand,ast.Compare)
|
| 381 |
+
and isinstance(node.op, ast.Not)
|
| 382 |
+
):
|
| 383 |
+
# work around for
|
| 384 |
+
# https://github.com/python/cpython/issues/114671
|
| 385 |
+
self.result = node.operand
|
| 386 |
+
|
| 387 |
+
@staticmethod
|
| 388 |
+
def is_except_cleanup(inst: dis.Instruction, node: EnhancedAST) -> bool:
|
| 389 |
+
if inst.opname not in (
|
| 390 |
+
"STORE_NAME",
|
| 391 |
+
"STORE_FAST",
|
| 392 |
+
"STORE_DEREF",
|
| 393 |
+
"STORE_GLOBAL",
|
| 394 |
+
"DELETE_NAME",
|
| 395 |
+
"DELETE_FAST",
|
| 396 |
+
"DELETE_DEREF",
|
| 397 |
+
"DELETE_GLOBAL",
|
| 398 |
+
):
|
| 399 |
+
return False
|
| 400 |
+
|
| 401 |
+
# This bytecode does something exception cleanup related.
|
| 402 |
+
# The position of the instruciton seems to be something in the last ast-node of the ExceptHandler
|
| 403 |
+
# this could be a bug, but it might not be observable in normal python code.
|
| 404 |
+
|
| 405 |
+
# example:
|
| 406 |
+
# except Exception as exc:
|
| 407 |
+
# enum_member._value_ = value
|
| 408 |
+
|
| 409 |
+
# other example:
|
| 410 |
+
# STORE_FAST of e was mapped to Constant(value=False)
|
| 411 |
+
# except OSError as e:
|
| 412 |
+
# if not _ignore_error(e):
|
| 413 |
+
# raise
|
| 414 |
+
# return False
|
| 415 |
+
|
| 416 |
+
# STORE_FAST of msg was mapped to print(...)
|
| 417 |
+
# except TypeError as msg:
|
| 418 |
+
# print("Sorry:", msg, file=file)
|
| 419 |
+
|
| 420 |
+
if (
|
| 421 |
+
isinstance(node, ast.Name)
|
| 422 |
+
and isinstance(node.ctx,ast.Store)
|
| 423 |
+
and inst.opname.startswith("STORE_")
|
| 424 |
+
and mangled_name(node) == inst.argval
|
| 425 |
+
):
|
| 426 |
+
# Storing the variable is valid and no exception cleanup, if the name is correct
|
| 427 |
+
return False
|
| 428 |
+
|
| 429 |
+
if (
|
| 430 |
+
isinstance(node, ast.Name)
|
| 431 |
+
and isinstance(node.ctx,ast.Del)
|
| 432 |
+
and inst.opname.startswith("DELETE_")
|
| 433 |
+
and mangled_name(node) == inst.argval
|
| 434 |
+
):
|
| 435 |
+
# Deleting the variable is valid and no exception cleanup, if the name is correct
|
| 436 |
+
return False
|
| 437 |
+
|
| 438 |
+
return any(
|
| 439 |
+
isinstance(n, ast.ExceptHandler) and n.name and mangled_name(n) == inst.argval
|
| 440 |
+
for n in parents(node)
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
def verify(self, node: EnhancedAST, instruction: dis.Instruction) -> None:
|
| 444 |
+
"""
|
| 445 |
+
checks if this node could gererate this instruction
|
| 446 |
+
"""
|
| 447 |
+
|
| 448 |
+
op_name = instruction.opname
|
| 449 |
+
extra_filter: Callable[[EnhancedAST], bool] = lambda e: True
|
| 450 |
+
ctx: Type = type(None)
|
| 451 |
+
|
| 452 |
+
def inst_match(opnames: Union[str, Sequence[str]], **kwargs: Any) -> bool:
|
| 453 |
+
"""
|
| 454 |
+
match instruction
|
| 455 |
+
|
| 456 |
+
Parameters:
|
| 457 |
+
opnames: (str|Seq[str]): inst.opname has to be equal to or in `opname`
|
| 458 |
+
**kwargs: every arg has to match inst.arg
|
| 459 |
+
|
| 460 |
+
Returns:
|
| 461 |
+
True if all conditions match the instruction
|
| 462 |
+
|
| 463 |
+
"""
|
| 464 |
+
|
| 465 |
+
if isinstance(opnames, str):
|
| 466 |
+
opnames = [opnames]
|
| 467 |
+
return instruction.opname in opnames and kwargs == {
|
| 468 |
+
k: getattr(instruction, k) for k in kwargs
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
def node_match(node_type: Union[Type, Tuple[Type, ...]], **kwargs: Any) -> bool:
|
| 472 |
+
"""
|
| 473 |
+
match the ast-node
|
| 474 |
+
|
| 475 |
+
Parameters:
|
| 476 |
+
node_type: type of the node
|
| 477 |
+
**kwargs: every `arg` has to be equal `node.arg`
|
| 478 |
+
or `node.arg` has to be an instance of `arg` if it is a type.
|
| 479 |
+
"""
|
| 480 |
+
return isinstance(node, node_type) and all(
|
| 481 |
+
isinstance(getattr(node, k), v)
|
| 482 |
+
if isinstance(v, type)
|
| 483 |
+
else getattr(node, k) == v
|
| 484 |
+
for k, v in kwargs.items()
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
if op_name == "CACHE":
|
| 488 |
+
return
|
| 489 |
+
|
| 490 |
+
if inst_match("CALL") and node_match((ast.With, ast.AsyncWith)):
|
| 491 |
+
# call to context.__exit__
|
| 492 |
+
return
|
| 493 |
+
|
| 494 |
+
if inst_match(("CALL", "LOAD_FAST")) and node_match(
|
| 495 |
+
(ast.ListComp, ast.GeneratorExp, ast.SetComp, ast.DictComp)
|
| 496 |
+
):
|
| 497 |
+
# call to the generator function
|
| 498 |
+
return
|
| 499 |
+
|
| 500 |
+
if (
|
| 501 |
+
sys.version_info >= (3, 12)
|
| 502 |
+
and inst_match(("LOAD_FAST_AND_CLEAR", "STORE_FAST"))
|
| 503 |
+
and node_match((ast.ListComp, ast.SetComp, ast.DictComp))
|
| 504 |
+
):
|
| 505 |
+
return
|
| 506 |
+
|
| 507 |
+
if inst_match(("CALL", "CALL_FUNCTION_EX")) and node_match(
|
| 508 |
+
(ast.ClassDef, ast.Call)
|
| 509 |
+
):
|
| 510 |
+
return
|
| 511 |
+
|
| 512 |
+
if inst_match(("COMPARE_OP", "IS_OP", "CONTAINS_OP")) and node_match(
|
| 513 |
+
ast.Compare
|
| 514 |
+
):
|
| 515 |
+
return
|
| 516 |
+
|
| 517 |
+
if inst_match("LOAD_NAME", argval="__annotations__") and node_match(
|
| 518 |
+
ast.AnnAssign
|
| 519 |
+
):
|
| 520 |
+
return
|
| 521 |
+
|
| 522 |
+
if (
|
| 523 |
+
(
|
| 524 |
+
inst_match("LOAD_METHOD", argval="join")
|
| 525 |
+
or inst_match("LOAD_ATTR", argval="join") # 3.12
|
| 526 |
+
or inst_match(("CALL", "BUILD_STRING"))
|
| 527 |
+
)
|
| 528 |
+
and node_match(ast.BinOp, left=ast.Constant, op=ast.Mod)
|
| 529 |
+
and isinstance(cast(ast.Constant, cast(ast.BinOp, node).left).value, str)
|
| 530 |
+
):
|
| 531 |
+
# "..."%(...) uses "".join
|
| 532 |
+
return
|
| 533 |
+
|
| 534 |
+
if inst_match("STORE_SUBSCR") and node_match(ast.AnnAssign):
|
| 535 |
+
# data: int
|
| 536 |
+
return
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
if inst_match(("DELETE_NAME", "DELETE_FAST")) and node_match(
|
| 540 |
+
ast.Name, id=instruction.argval, ctx=ast.Del
|
| 541 |
+
):
|
| 542 |
+
return
|
| 543 |
+
|
| 544 |
+
if inst_match("BUILD_STRING") and (
|
| 545 |
+
node_match(ast.JoinedStr) or node_match(ast.BinOp, op=ast.Mod)
|
| 546 |
+
):
|
| 547 |
+
return
|
| 548 |
+
|
| 549 |
+
if inst_match(("BEFORE_WITH","WITH_EXCEPT_START")) and node_match(ast.With):
|
| 550 |
+
return
|
| 551 |
+
|
| 552 |
+
if inst_match(("STORE_NAME", "STORE_GLOBAL"), argval="__doc__") and node_match(
|
| 553 |
+
ast.Constant
|
| 554 |
+
):
|
| 555 |
+
# store docstrings
|
| 556 |
+
return
|
| 557 |
+
|
| 558 |
+
if (
|
| 559 |
+
inst_match(("STORE_NAME", "STORE_FAST", "STORE_GLOBAL", "STORE_DEREF"))
|
| 560 |
+
and node_match(ast.ExceptHandler)
|
| 561 |
+
and instruction.argval == mangled_name(node)
|
| 562 |
+
):
|
| 563 |
+
# store exception in variable
|
| 564 |
+
return
|
| 565 |
+
|
| 566 |
+
if (
|
| 567 |
+
inst_match(("STORE_NAME", "STORE_FAST", "STORE_DEREF", "STORE_GLOBAL"))
|
| 568 |
+
and node_match((ast.Import, ast.ImportFrom))
|
| 569 |
+
and any(mangled_name(cast(EnhancedAST, alias)) == instruction.argval for alias in cast(ast.Import, node).names)
|
| 570 |
+
):
|
| 571 |
+
# store imported module in variable
|
| 572 |
+
return
|
| 573 |
+
|
| 574 |
+
if (
|
| 575 |
+
inst_match(("STORE_FAST", "STORE_DEREF", "STORE_NAME", "STORE_GLOBAL"))
|
| 576 |
+
and (
|
| 577 |
+
node_match((ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef))
|
| 578 |
+
or node_match(
|
| 579 |
+
ast.Name,
|
| 580 |
+
ctx=ast.Store,
|
| 581 |
+
)
|
| 582 |
+
)
|
| 583 |
+
and instruction.argval == mangled_name(node)
|
| 584 |
+
):
|
| 585 |
+
return
|
| 586 |
+
|
| 587 |
+
if False:
|
| 588 |
+
# TODO: match expressions are not supported for now
|
| 589 |
+
if inst_match(("STORE_FAST", "STORE_NAME")) and node_match(
|
| 590 |
+
ast.MatchAs, name=instruction.argval
|
| 591 |
+
):
|
| 592 |
+
return
|
| 593 |
+
|
| 594 |
+
if inst_match("COMPARE_OP", argval="==") and node_match(ast.MatchSequence):
|
| 595 |
+
return
|
| 596 |
+
|
| 597 |
+
if inst_match("COMPARE_OP", argval="==") and node_match(ast.MatchValue):
|
| 598 |
+
return
|
| 599 |
+
|
| 600 |
+
if inst_match("BINARY_OP") and node_match(
|
| 601 |
+
ast.AugAssign, op=op_type_map[instruction.argrepr.removesuffix("=")]
|
| 602 |
+
):
|
| 603 |
+
# a+=5
|
| 604 |
+
return
|
| 605 |
+
|
| 606 |
+
if node_match(ast.Attribute, ctx=ast.Del) and inst_match(
|
| 607 |
+
"DELETE_ATTR", argval=mangled_name(node)
|
| 608 |
+
):
|
| 609 |
+
return
|
| 610 |
+
|
| 611 |
+
if inst_match(
|
| 612 |
+
(
|
| 613 |
+
"JUMP_IF_TRUE_OR_POP",
|
| 614 |
+
"JUMP_IF_FALSE_OR_POP",
|
| 615 |
+
"POP_JUMP_IF_TRUE",
|
| 616 |
+
"POP_JUMP_IF_FALSE",
|
| 617 |
+
)
|
| 618 |
+
) and node_match(ast.BoolOp):
|
| 619 |
+
# and/or short circuit
|
| 620 |
+
return
|
| 621 |
+
|
| 622 |
+
if inst_match("DELETE_SUBSCR") and node_match(ast.Subscript, ctx=ast.Del):
|
| 623 |
+
return
|
| 624 |
+
|
| 625 |
+
if (
|
| 626 |
+
node_match(ast.Name, ctx=ast.Load)
|
| 627 |
+
or (
|
| 628 |
+
node_match(ast.Name, ctx=ast.Store)
|
| 629 |
+
and isinstance(node.parent, ast.AugAssign)
|
| 630 |
+
)
|
| 631 |
+
) and inst_match(
|
| 632 |
+
(
|
| 633 |
+
"LOAD_NAME",
|
| 634 |
+
"LOAD_FAST",
|
| 635 |
+
"LOAD_FAST_CHECK",
|
| 636 |
+
"LOAD_GLOBAL",
|
| 637 |
+
"LOAD_DEREF",
|
| 638 |
+
"LOAD_FROM_DICT_OR_DEREF",
|
| 639 |
+
),
|
| 640 |
+
argval=mangled_name(node),
|
| 641 |
+
):
|
| 642 |
+
return
|
| 643 |
+
|
| 644 |
+
if node_match(ast.Name, ctx=ast.Del) and inst_match(
|
| 645 |
+
("DELETE_NAME", "DELETE_GLOBAL", "DELETE_DEREF"), argval=mangled_name(node)
|
| 646 |
+
):
|
| 647 |
+
return
|
| 648 |
+
|
| 649 |
+
if node_match(ast.Constant) and inst_match(
|
| 650 |
+
"LOAD_CONST", argval=cast(ast.Constant, node).value
|
| 651 |
+
):
|
| 652 |
+
return
|
| 653 |
+
|
| 654 |
+
if node_match(
|
| 655 |
+
(ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp, ast.For)
|
| 656 |
+
) and inst_match(("GET_ITER", "FOR_ITER")):
|
| 657 |
+
return
|
| 658 |
+
|
| 659 |
+
if sys.version_info >= (3, 12):
|
| 660 |
+
if node_match(ast.UnaryOp, op=ast.UAdd) and inst_match(
|
| 661 |
+
"CALL_INTRINSIC_1", argrepr="INTRINSIC_UNARY_POSITIVE"
|
| 662 |
+
):
|
| 663 |
+
return
|
| 664 |
+
|
| 665 |
+
if node_match(ast.Subscript) and inst_match("BINARY_SLICE"):
|
| 666 |
+
return
|
| 667 |
+
|
| 668 |
+
if node_match(ast.ImportFrom) and inst_match(
|
| 669 |
+
"CALL_INTRINSIC_1", argrepr="INTRINSIC_IMPORT_STAR"
|
| 670 |
+
):
|
| 671 |
+
return
|
| 672 |
+
|
| 673 |
+
if (
|
| 674 |
+
node_match(ast.Yield) or isinstance(node.parent, ast.GeneratorExp)
|
| 675 |
+
) and inst_match("CALL_INTRINSIC_1", argrepr="INTRINSIC_ASYNC_GEN_WRAP"):
|
| 676 |
+
return
|
| 677 |
+
|
| 678 |
+
if node_match(ast.Name) and inst_match("LOAD_DEREF",argval="__classdict__"):
|
| 679 |
+
return
|
| 680 |
+
|
| 681 |
+
if node_match(ast.TypeVar) and (
|
| 682 |
+
inst_match("CALL_INTRINSIC_1", argrepr="INTRINSIC_TYPEVAR")
|
| 683 |
+
or inst_match(
|
| 684 |
+
"CALL_INTRINSIC_2", argrepr="INTRINSIC_TYPEVAR_WITH_BOUND"
|
| 685 |
+
)
|
| 686 |
+
or inst_match(
|
| 687 |
+
"CALL_INTRINSIC_2", argrepr="INTRINSIC_TYPEVAR_WITH_CONSTRAINTS"
|
| 688 |
+
)
|
| 689 |
+
or inst_match(("STORE_FAST", "STORE_DEREF"), argrepr=mangled_name(node))
|
| 690 |
+
):
|
| 691 |
+
return
|
| 692 |
+
|
| 693 |
+
if node_match(ast.TypeVarTuple) and (
|
| 694 |
+
inst_match("CALL_INTRINSIC_1", argrepr="INTRINSIC_TYPEVARTUPLE")
|
| 695 |
+
or inst_match(("STORE_FAST", "STORE_DEREF"), argrepr=node.name)
|
| 696 |
+
):
|
| 697 |
+
return
|
| 698 |
+
|
| 699 |
+
if node_match(ast.ParamSpec) and (
|
| 700 |
+
inst_match("CALL_INTRINSIC_1", argrepr="INTRINSIC_PARAMSPEC")
|
| 701 |
+
|
| 702 |
+
or inst_match(("STORE_FAST", "STORE_DEREF"), argrepr=node.name)):
|
| 703 |
+
return
|
| 704 |
+
|
| 705 |
+
|
| 706 |
+
if node_match(ast.TypeAlias):
|
| 707 |
+
if(
|
| 708 |
+
inst_match("CALL_INTRINSIC_1", argrepr="INTRINSIC_TYPEALIAS")
|
| 709 |
+
or inst_match(
|
| 710 |
+
("STORE_NAME", "STORE_FAST", "STORE_DEREF"), argrepr=node.name.id
|
| 711 |
+
)
|
| 712 |
+
or inst_match("CALL")
|
| 713 |
+
):
|
| 714 |
+
return
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
if node_match(ast.ClassDef) and node.type_params:
|
| 718 |
+
if inst_match(
|
| 719 |
+
("STORE_DEREF", "LOAD_DEREF", "LOAD_FROM_DICT_OR_DEREF"),
|
| 720 |
+
argrepr=".type_params",
|
| 721 |
+
):
|
| 722 |
+
return
|
| 723 |
+
|
| 724 |
+
if inst_match(("STORE_FAST", "LOAD_FAST"), argrepr=".generic_base"):
|
| 725 |
+
return
|
| 726 |
+
|
| 727 |
+
if inst_match(
|
| 728 |
+
"CALL_INTRINSIC_1", argrepr="INTRINSIC_SUBSCRIPT_GENERIC"
|
| 729 |
+
):
|
| 730 |
+
return
|
| 731 |
+
|
| 732 |
+
if inst_match("LOAD_DEREF",argval="__classdict__"):
|
| 733 |
+
return
|
| 734 |
+
|
| 735 |
+
if node_match((ast.FunctionDef,ast.AsyncFunctionDef)) and node.type_params:
|
| 736 |
+
if inst_match("CALL"):
|
| 737 |
+
return
|
| 738 |
+
|
| 739 |
+
if inst_match(
|
| 740 |
+
"CALL_INTRINSIC_2", argrepr="INTRINSIC_SET_FUNCTION_TYPE_PARAMS"
|
| 741 |
+
):
|
| 742 |
+
return
|
| 743 |
+
|
| 744 |
+
if inst_match("LOAD_FAST",argval=".defaults"):
|
| 745 |
+
return
|
| 746 |
+
|
| 747 |
+
if inst_match("LOAD_FAST",argval=".kwdefaults"):
|
| 748 |
+
return
|
| 749 |
+
|
| 750 |
+
if inst_match("STORE_NAME", argval="__classdictcell__"):
|
| 751 |
+
# this is a general thing
|
| 752 |
+
return
|
| 753 |
+
|
| 754 |
+
|
| 755 |
+
# f-strings
|
| 756 |
+
|
| 757 |
+
if node_match(ast.JoinedStr) and (
|
| 758 |
+
inst_match("LOAD_ATTR", argval="join")
|
| 759 |
+
or inst_match(("LIST_APPEND", "CALL"))
|
| 760 |
+
):
|
| 761 |
+
return
|
| 762 |
+
|
| 763 |
+
if node_match(ast.FormattedValue) and inst_match("FORMAT_VALUE"):
|
| 764 |
+
return
|
| 765 |
+
|
| 766 |
+
if sys.version_info >= (3, 13):
|
| 767 |
+
|
| 768 |
+
if inst_match("NOP"):
|
| 769 |
+
return
|
| 770 |
+
|
| 771 |
+
if inst_match("TO_BOOL") and node_match(ast.BoolOp):
|
| 772 |
+
return
|
| 773 |
+
|
| 774 |
+
if inst_match("CALL_KW") and node_match((ast.Call, ast.ClassDef)):
|
| 775 |
+
return
|
| 776 |
+
|
| 777 |
+
if inst_match("LOAD_FAST", argval=".type_params"):
|
| 778 |
+
return
|
| 779 |
+
|
| 780 |
+
if inst_match("LOAD_FAST", argval="__classdict__"):
|
| 781 |
+
return
|
| 782 |
+
|
| 783 |
+
if inst_match("LOAD_FAST") and node_match(
|
| 784 |
+
(
|
| 785 |
+
ast.FunctionDef,
|
| 786 |
+
ast.ClassDef,
|
| 787 |
+
ast.TypeAlias,
|
| 788 |
+
ast.TypeVar,
|
| 789 |
+
ast.Lambda,
|
| 790 |
+
ast.AsyncFunctionDef,
|
| 791 |
+
)
|
| 792 |
+
):
|
| 793 |
+
# These are loads for closure variables.
|
| 794 |
+
# It is difficult to check that this is actually closure variable, see:
|
| 795 |
+
# https://github.com/alexmojaki/executing/pull/80#discussion_r1716027317
|
| 796 |
+
return
|
| 797 |
+
|
| 798 |
+
if (
|
| 799 |
+
inst_match("LOAD_FAST")
|
| 800 |
+
and node_match(ast.TypeAlias)
|
| 801 |
+
and node.name.id == instruction.argval
|
| 802 |
+
):
|
| 803 |
+
return
|
| 804 |
+
|
| 805 |
+
if inst_match("STORE_NAME",argval="__static_attributes__"):
|
| 806 |
+
# the node is the first node in the body
|
| 807 |
+
return
|
| 808 |
+
|
| 809 |
+
if inst_match("LOAD_FAST") and isinstance(node.parent,ast.TypeVar):
|
| 810 |
+
return
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
# old verifier
|
| 814 |
+
|
| 815 |
+
typ: Type = type(None)
|
| 816 |
+
op_type: Type = type(None)
|
| 817 |
+
|
| 818 |
+
if op_name.startswith(("BINARY_SUBSCR", "SLICE+")):
|
| 819 |
+
typ = ast.Subscript
|
| 820 |
+
ctx = ast.Load
|
| 821 |
+
elif op_name.startswith("BINARY_"):
|
| 822 |
+
typ = ast.BinOp
|
| 823 |
+
op_type = op_type_map[instruction.argrepr]
|
| 824 |
+
extra_filter = lambda e: isinstance(cast(ast.BinOp, e).op, op_type)
|
| 825 |
+
elif op_name.startswith("UNARY_"):
|
| 826 |
+
typ = ast.UnaryOp
|
| 827 |
+
op_type = dict(
|
| 828 |
+
UNARY_POSITIVE=ast.UAdd,
|
| 829 |
+
UNARY_NEGATIVE=ast.USub,
|
| 830 |
+
UNARY_NOT=ast.Not,
|
| 831 |
+
UNARY_INVERT=ast.Invert,
|
| 832 |
+
)[op_name]
|
| 833 |
+
extra_filter = lambda e: isinstance(cast(ast.UnaryOp, e).op, op_type)
|
| 834 |
+
elif op_name in ("LOAD_ATTR", "LOAD_METHOD", "LOOKUP_METHOD","LOAD_SUPER_ATTR"):
|
| 835 |
+
typ = ast.Attribute
|
| 836 |
+
ctx = ast.Load
|
| 837 |
+
extra_filter = lambda e: mangled_name(e) == instruction.argval
|
| 838 |
+
elif op_name in (
|
| 839 |
+
"LOAD_NAME",
|
| 840 |
+
"LOAD_GLOBAL",
|
| 841 |
+
"LOAD_FAST",
|
| 842 |
+
"LOAD_DEREF",
|
| 843 |
+
"LOAD_CLASSDEREF",
|
| 844 |
+
):
|
| 845 |
+
typ = ast.Name
|
| 846 |
+
ctx = ast.Load
|
| 847 |
+
extra_filter = lambda e: cast(ast.Name, e).id == instruction.argval
|
| 848 |
+
elif op_name in ("COMPARE_OP", "IS_OP", "CONTAINS_OP"):
|
| 849 |
+
typ = ast.Compare
|
| 850 |
+
extra_filter = lambda e: len(cast(ast.Compare, e).ops) == 1
|
| 851 |
+
elif op_name.startswith(("STORE_SLICE", "STORE_SUBSCR")):
|
| 852 |
+
ctx = ast.Store
|
| 853 |
+
typ = ast.Subscript
|
| 854 |
+
elif op_name.startswith("STORE_ATTR"):
|
| 855 |
+
ctx = ast.Store
|
| 856 |
+
typ = ast.Attribute
|
| 857 |
+
extra_filter = lambda e: mangled_name(e) == instruction.argval
|
| 858 |
+
|
| 859 |
+
node_ctx = getattr(node, "ctx", None)
|
| 860 |
+
|
| 861 |
+
ctx_match = (
|
| 862 |
+
ctx is not type(None)
|
| 863 |
+
or not hasattr(node, "ctx")
|
| 864 |
+
or isinstance(node_ctx, ctx)
|
| 865 |
+
)
|
| 866 |
+
|
| 867 |
+
# check for old verifier
|
| 868 |
+
if isinstance(node, typ) and ctx_match and extra_filter(node):
|
| 869 |
+
return
|
| 870 |
+
|
| 871 |
+
# generate error
|
| 872 |
+
|
| 873 |
+
title = "ast.%s is not created from %s" % (
|
| 874 |
+
type(node).__name__,
|
| 875 |
+
instruction.opname,
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
raise VerifierFailure(title, node, instruction)
|
| 879 |
+
|
| 880 |
+
def instruction(self, index: int) -> Optional[dis.Instruction]:
|
| 881 |
+
return self.bc_dict.get(index,None)
|
| 882 |
+
|
| 883 |
+
def opname(self, index: int) -> str:
|
| 884 |
+
i=self.instruction(index)
|
| 885 |
+
if i is None:
|
| 886 |
+
return "CACHE"
|
| 887 |
+
return i.opname
|
| 888 |
+
|
| 889 |
+
extra_node_types=()
|
| 890 |
+
if sys.version_info >= (3,12):
|
| 891 |
+
extra_node_types = (ast.type_param,)
|
| 892 |
+
|
| 893 |
+
def find_node(
|
| 894 |
+
self,
|
| 895 |
+
index: int,
|
| 896 |
+
match_positions: Sequence[str] = (
|
| 897 |
+
"lineno",
|
| 898 |
+
"end_lineno",
|
| 899 |
+
"col_offset",
|
| 900 |
+
"end_col_offset",
|
| 901 |
+
),
|
| 902 |
+
typ: tuple[Type, ...] = (
|
| 903 |
+
ast.expr,
|
| 904 |
+
ast.stmt,
|
| 905 |
+
ast.excepthandler,
|
| 906 |
+
ast.pattern,
|
| 907 |
+
*extra_node_types,
|
| 908 |
+
),
|
| 909 |
+
) -> EnhancedAST:
|
| 910 |
+
instruction = self.instruction(index)
|
| 911 |
+
assert instruction is not None
|
| 912 |
+
|
| 913 |
+
position = instruction.positions
|
| 914 |
+
assert position is not None and position.lineno is not None
|
| 915 |
+
|
| 916 |
+
return only(
|
| 917 |
+
cast(EnhancedAST, node)
|
| 918 |
+
for node in self.source._nodes_by_line[position.lineno]
|
| 919 |
+
if isinstance(node, typ)
|
| 920 |
+
if not isinstance(node, ast.Expr)
|
| 921 |
+
# matchvalue.value has the same positions as matchvalue themself, so we exclude ast.MatchValue
|
| 922 |
+
if not isinstance(node, ast.MatchValue)
|
| 923 |
+
if all(
|
| 924 |
+
getattr(position, attr) == getattr(node, attr)
|
| 925 |
+
for attr in match_positions
|
| 926 |
+
)
|
| 927 |
+
)
|
evalkit_tf446/lib/python3.10/site-packages/ninja-1.11.1.1.dist-info/LICENSE_Apache_20
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction, and
|
| 10 |
+
distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
| 13 |
+
owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
| 16 |
+
that control, are controlled by, or are under common control with that entity.
|
| 17 |
+
For the purposes of this definition, "control" means (i) the power, direct or
|
| 18 |
+
indirect, to cause the direction or management of such entity, whether by
|
| 19 |
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 20 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 21 |
+
|
| 22 |
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
| 23 |
+
permissions granted by this License.
|
| 24 |
+
|
| 25 |
+
"Source" form shall mean the preferred form for making modifications, including
|
| 26 |
+
but not limited to software source code, documentation source, and configuration
|
| 27 |
+
files.
|
| 28 |
+
|
| 29 |
+
"Object" form shall mean any form resulting from mechanical transformation or
|
| 30 |
+
translation of a Source form, including but not limited to compiled object code,
|
| 31 |
+
generated documentation, and conversions to other media types.
|
| 32 |
+
|
| 33 |
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
| 34 |
+
available under the License, as indicated by a copyright notice that is included
|
| 35 |
+
in or attached to the work (an example is provided in the Appendix below).
|
| 36 |
+
|
| 37 |
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
| 38 |
+
is based on (or derived from) the Work and for which the editorial revisions,
|
| 39 |
+
annotations, elaborations, or other modifications represent, as a whole, an
|
| 40 |
+
original work of authorship. For the purposes of this License, Derivative Works
|
| 41 |
+
shall not include works that remain separable from, or merely link (or bind by
|
| 42 |
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
| 43 |
+
|
| 44 |
+
"Contribution" shall mean any work of authorship, including the original version
|
| 45 |
+
of the Work and any modifications or additions to that Work or Derivative Works
|
| 46 |
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
| 47 |
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
| 48 |
+
on behalf of the copyright owner. For the purposes of this definition,
|
| 49 |
+
"submitted" means any form of electronic, verbal, or written communication sent
|
| 50 |
+
to the Licensor or its representatives, including but not limited to
|
| 51 |
+
communication on electronic mailing lists, source code control systems, and
|
| 52 |
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
| 53 |
+
the purpose of discussing and improving the Work, but excluding communication
|
| 54 |
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
| 55 |
+
owner as "Not a Contribution."
|
| 56 |
+
|
| 57 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
| 58 |
+
of whom a Contribution has been received by Licensor and subsequently
|
| 59 |
+
incorporated within the Work.
|
| 60 |
+
|
| 61 |
+
2. Grant of Copyright License.
|
| 62 |
+
|
| 63 |
+
Subject to the terms and conditions of this License, each Contributor hereby
|
| 64 |
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
| 65 |
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
| 66 |
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
| 67 |
+
Derivative Works in Source or Object form.
|
| 68 |
+
|
| 69 |
+
3. Grant of Patent License.
|
| 70 |
+
|
| 71 |
+
Subject to the terms and conditions of this License, each Contributor hereby
|
| 72 |
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
| 73 |
+
irrevocable (except as stated in this section) patent license to make, have
|
| 74 |
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
| 75 |
+
such license applies only to those patent claims licensable by such Contributor
|
| 76 |
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
| 77 |
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
| 78 |
+
submitted. If You institute patent litigation against any entity (including a
|
| 79 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
| 80 |
+
Contribution incorporated within the Work constitutes direct or contributory
|
| 81 |
+
patent infringement, then any patent licenses granted to You under this License
|
| 82 |
+
for that Work shall terminate as of the date such litigation is filed.
|
| 83 |
+
|
| 84 |
+
4. Redistribution.
|
| 85 |
+
|
| 86 |
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
| 87 |
+
in any medium, with or without modifications, and in Source or Object form,
|
| 88 |
+
provided that You meet the following conditions:
|
| 89 |
+
|
| 90 |
+
You must give any other recipients of the Work or Derivative Works a copy of
|
| 91 |
+
this License; and
|
| 92 |
+
You must cause any modified files to carry prominent notices stating that You
|
| 93 |
+
changed the files; and
|
| 94 |
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
| 95 |
+
all copyright, patent, trademark, and attribution notices from the Source form
|
| 96 |
+
of the Work, excluding those notices that do not pertain to any part of the
|
| 97 |
+
Derivative Works; and
|
| 98 |
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
| 99 |
+
Derivative Works that You distribute must include a readable copy of the
|
| 100 |
+
attribution notices contained within such NOTICE file, excluding those notices
|
| 101 |
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
| 102 |
+
following places: within a NOTICE text file distributed as part of the
|
| 103 |
+
Derivative Works; within the Source form or documentation, if provided along
|
| 104 |
+
with the Derivative Works; or, within a display generated by the Derivative
|
| 105 |
+
Works, if and wherever such third-party notices normally appear. The contents of
|
| 106 |
+
the NOTICE file are for informational purposes only and do not modify the
|
| 107 |
+
License. You may add Your own attribution notices within Derivative Works that
|
| 108 |
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
| 109 |
+
provided that such additional attribution notices cannot be construed as
|
| 110 |
+
modifying the License.
|
| 111 |
+
You may add Your own copyright statement to Your modifications and may provide
|
| 112 |
+
additional or different license terms and conditions for use, reproduction, or
|
| 113 |
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
| 114 |
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
| 115 |
+
with the conditions stated in this License.
|
| 116 |
+
|
| 117 |
+
5. Submission of Contributions.
|
| 118 |
+
|
| 119 |
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
| 120 |
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
| 121 |
+
conditions of this License, without any additional terms or conditions.
|
| 122 |
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
| 123 |
+
any separate license agreement you may have executed with Licensor regarding
|
| 124 |
+
such Contributions.
|
| 125 |
+
|
| 126 |
+
6. Trademarks.
|
| 127 |
+
|
| 128 |
+
This License does not grant permission to use the trade names, trademarks,
|
| 129 |
+
service marks, or product names of the Licensor, except as required for
|
| 130 |
+
reasonable and customary use in describing the origin of the Work and
|
| 131 |
+
reproducing the content of the NOTICE file.
|
| 132 |
+
|
| 133 |
+
7. Disclaimer of Warranty.
|
| 134 |
+
|
| 135 |
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
| 136 |
+
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 137 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
| 138 |
+
including, without limitation, any warranties or conditions of TITLE,
|
| 139 |
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
| 140 |
+
solely responsible for determining the appropriateness of using or
|
| 141 |
+
redistributing the Work and assume any risks associated with Your exercise of
|
| 142 |
+
permissions under this License.
|
| 143 |
+
|
| 144 |
+
8. Limitation of Liability.
|
| 145 |
+
|
| 146 |
+
In no event and under no legal theory, whether in tort (including negligence),
|
| 147 |
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
| 148 |
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
| 149 |
+
liable to You for damages, including any direct, indirect, special, incidental,
|
| 150 |
+
or consequential damages of any character arising as a result of this License or
|
| 151 |
+
out of the use or inability to use the Work (including but not limited to
|
| 152 |
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
| 153 |
+
any and all other commercial damages or losses), even if such Contributor has
|
| 154 |
+
been advised of the possibility of such damages.
|
| 155 |
+
|
| 156 |
+
9. Accepting Warranty or Additional Liability.
|
| 157 |
+
|
| 158 |
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
| 159 |
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
| 160 |
+
other liability obligations and/or rights consistent with this License. However,
|
| 161 |
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
| 162 |
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
| 163 |
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
| 164 |
+
incurred by, or claims asserted against, such Contributor by reason of your
|
| 165 |
+
accepting any such warranty or additional liability.
|
| 166 |
+
|
| 167 |
+
END OF TERMS AND CONDITIONS
|
| 168 |
+
|
| 169 |
+
APPENDIX: How to apply the Apache License to your work
|
| 170 |
+
|
| 171 |
+
To apply the Apache License to your work, attach the following boilerplate
|
| 172 |
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
| 173 |
+
identifying information. (Don't include the brackets!) The text should be
|
| 174 |
+
enclosed in the appropriate comment syntax for the file format. We also
|
| 175 |
+
recommend that a file or class name and description of purpose be included on
|
| 176 |
+
the same "printed page" as the copyright notice for easier identification within
|
| 177 |
+
third-party archives.
|
| 178 |
+
|
| 179 |
+
Copyright [yyyy] [name of copyright owner]
|
| 180 |
+
|
| 181 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 182 |
+
you may not use this file except in compliance with the License.
|
| 183 |
+
You may obtain a copy of the License at
|
| 184 |
+
|
| 185 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 186 |
+
|
| 187 |
+
Unless required by applicable law or agreed to in writing, software
|
| 188 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 189 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 190 |
+
See the License for the specific language governing permissions and
|
| 191 |
+
limitations under the License.
|
evalkit_tf446/lib/python3.10/site-packages/ninja-1.11.1.1.dist-info/RECORD
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/ninja,sha256=dPQZGK1zsCFizOm9F0Be4XTXFwGOSmnmAbG5C1Sgp44,225
|
| 2 |
+
ninja-1.11.1.1.dist-info/AUTHORS.rst,sha256=bGE1t_Lhm2ir8S7n_jbLDohP84fpJ5sNCuxvDVsKNQg,142
|
| 3 |
+
ninja-1.11.1.1.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 4 |
+
ninja-1.11.1.1.dist-info/LICENSE_Apache_20,sha256=c7p036pSC0mkAbXSFFmoUjoUbzt1GKgz7qXvqFEwv2g,10273
|
| 5 |
+
ninja-1.11.1.1.dist-info/METADATA,sha256=FNmvFHa9nvpkX88umdMPsIPHYaalZdrK-QQpzjU9wmY,5334
|
| 6 |
+
ninja-1.11.1.1.dist-info/RECORD,,
|
| 7 |
+
ninja-1.11.1.1.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 8 |
+
ninja-1.11.1.1.dist-info/WHEEL,sha256=6Eze_7Ff58FNfPcaZbQizFyBddeECOgzc1JG4XzqHnE,211
|
| 9 |
+
ninja-1.11.1.1.dist-info/entry_points.txt,sha256=zZQG_ZObDvtm-DUhgcGr4lCsN6T96aAvS7DcFarSSiM,38
|
| 10 |
+
ninja-1.11.1.1.dist-info/top_level.txt,sha256=AaPljJrazyz43svwe5IEyrCImzMf0IMbUnwKTE9prk0,6
|
| 11 |
+
ninja/__init__.py,sha256=j_kzDyrs3V8naSvwZvCyvdFRTMAjsC2LoYSusrUAWdM,1813
|
| 12 |
+
ninja/__main__.py,sha256=1KdgPQuHitlizLDhR9OBnSqU4Xxz5qsLKBPL-0iO7YY,88
|
| 13 |
+
ninja/__pycache__/__init__.cpython-310.pyc,,
|
| 14 |
+
ninja/__pycache__/__main__.cpython-310.pyc,,
|
| 15 |
+
ninja/__pycache__/_version.cpython-310.pyc,,
|
| 16 |
+
ninja/__pycache__/ninja_syntax.cpython-310.pyc,,
|
| 17 |
+
ninja/_version.py,sha256=njmJADvfXAMTU4TMCcGO1-JXTIz2qa9d_IguSNeV9uQ,418
|
| 18 |
+
ninja/data/bin/ninja,sha256=aPbDdcQjQwW_-XkKojKBWziSQ5DLtq1Jh-oPlK0rxBA,753192
|
| 19 |
+
ninja/ninja_syntax.py,sha256=AZt1YK1waQ_waJOZs42QhRBTP8pSwWhBc3nyIQEUGQk,6948
|
| 20 |
+
ninja/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (2.18 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (658 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/errors.cpython-310.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/parameters.cpython-310.pyc
ADDED
|
Binary file (16.8 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/request_validator.cpython-310.pyc
ADDED
|
Binary file (29.7 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/tokens.cpython-310.pyc
ADDED
|
Binary file (9.91 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (2.84 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
from .backend_application import BackendApplicationClient
|
| 10 |
+
from .base import AUTH_HEADER, BODY, URI_QUERY, Client
|
| 11 |
+
from .legacy_application import LegacyApplicationClient
|
| 12 |
+
from .mobile_application import MobileApplicationClient
|
| 13 |
+
from .service_application import ServiceApplicationClient
|
| 14 |
+
from .web_application import WebApplicationClient
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (767 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/backend_application.cpython-310.pyc
ADDED
|
Binary file (3.49 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (23.6 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/legacy_application.cpython-310.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/mobile_application.cpython-310.pyc
ADDED
|
Binary file (9.19 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/service_application.cpython-310.pyc
ADDED
|
Binary file (7.26 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/__pycache__/web_application.cpython-310.pyc
ADDED
|
Binary file (12.1 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/backend_application.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
from ..parameters import prepare_token_request
|
| 10 |
+
from .base import Client
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class BackendApplicationClient(Client):
|
| 14 |
+
|
| 15 |
+
"""A public client utilizing the client credentials grant workflow.
|
| 16 |
+
|
| 17 |
+
The client can request an access token using only its client
|
| 18 |
+
credentials (or other supported means of authentication) when the
|
| 19 |
+
client is requesting access to the protected resources under its
|
| 20 |
+
control, or those of another resource owner which has been previously
|
| 21 |
+
arranged with the authorization server (the method of which is beyond
|
| 22 |
+
the scope of this specification).
|
| 23 |
+
|
| 24 |
+
The client credentials grant type MUST only be used by confidential
|
| 25 |
+
clients.
|
| 26 |
+
|
| 27 |
+
Since the client authentication is used as the authorization grant,
|
| 28 |
+
no additional authorization request is needed.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
grant_type = 'client_credentials'
|
| 32 |
+
|
| 33 |
+
def prepare_request_body(self, body='', scope=None,
|
| 34 |
+
include_client_id=False, **kwargs):
|
| 35 |
+
"""Add the client credentials to the request body.
|
| 36 |
+
|
| 37 |
+
The client makes a request to the token endpoint by adding the
|
| 38 |
+
following parameters using the "application/x-www-form-urlencoded"
|
| 39 |
+
format per `Appendix B`_ in the HTTP request entity-body:
|
| 40 |
+
|
| 41 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 42 |
+
into. This may contain extra parameters. Default ''.
|
| 43 |
+
:param scope: The scope of the access request as described by
|
| 44 |
+
`Section 3.3`_.
|
| 45 |
+
|
| 46 |
+
:param include_client_id: `True` to send the `client_id` in the
|
| 47 |
+
body of the upstream request. This is required
|
| 48 |
+
if the client is not authenticating with the
|
| 49 |
+
authorization server as described in
|
| 50 |
+
`Section 3.2.1`_. False otherwise (default).
|
| 51 |
+
:type include_client_id: Boolean
|
| 52 |
+
|
| 53 |
+
:param kwargs: Extra credentials to include in the token request.
|
| 54 |
+
|
| 55 |
+
The client MUST authenticate with the authorization server as
|
| 56 |
+
described in `Section 3.2.1`_.
|
| 57 |
+
|
| 58 |
+
The prepared body will include all provided credentials as well as
|
| 59 |
+
the ``grant_type`` parameter set to ``client_credentials``::
|
| 60 |
+
|
| 61 |
+
>>> from oauthlib.oauth2 import BackendApplicationClient
|
| 62 |
+
>>> client = BackendApplicationClient('your_id')
|
| 63 |
+
>>> client.prepare_request_body(scope=['hello', 'world'])
|
| 64 |
+
'grant_type=client_credentials&scope=hello+world'
|
| 65 |
+
|
| 66 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 67 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 68 |
+
.. _`Section 3.2.1`: https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 69 |
+
"""
|
| 70 |
+
kwargs['client_id'] = self.client_id
|
| 71 |
+
kwargs['include_client_id'] = include_client_id
|
| 72 |
+
scope = self.scope if scope is None else scope
|
| 73 |
+
return prepare_token_request(self.grant_type, body=body,
|
| 74 |
+
scope=scope, **kwargs)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/base.py
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
import base64
|
| 10 |
+
import hashlib
|
| 11 |
+
import re
|
| 12 |
+
import secrets
|
| 13 |
+
import time
|
| 14 |
+
import warnings
|
| 15 |
+
|
| 16 |
+
from oauthlib.common import generate_token
|
| 17 |
+
from oauthlib.oauth2.rfc6749 import tokens
|
| 18 |
+
from oauthlib.oauth2.rfc6749.errors import (
|
| 19 |
+
InsecureTransportError, TokenExpiredError,
|
| 20 |
+
)
|
| 21 |
+
from oauthlib.oauth2.rfc6749.parameters import (
|
| 22 |
+
parse_token_response, prepare_token_request,
|
| 23 |
+
prepare_token_revocation_request,
|
| 24 |
+
)
|
| 25 |
+
from oauthlib.oauth2.rfc6749.utils import is_secure_transport
|
| 26 |
+
|
| 27 |
+
AUTH_HEADER = 'auth_header'
|
| 28 |
+
URI_QUERY = 'query'
|
| 29 |
+
BODY = 'body'
|
| 30 |
+
|
| 31 |
+
FORM_ENC_HEADERS = {
|
| 32 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class Client:
|
| 37 |
+
"""Base OAuth2 client responsible for access token management.
|
| 38 |
+
|
| 39 |
+
This class also acts as a generic interface providing methods common to all
|
| 40 |
+
client types such as ``prepare_authorization_request`` and
|
| 41 |
+
``prepare_token_revocation_request``. The ``prepare_x_request`` methods are
|
| 42 |
+
the recommended way of interacting with clients (as opposed to the abstract
|
| 43 |
+
prepare uri/body/etc methods). They are recommended over the older set
|
| 44 |
+
because they are easier to use (more consistent) and add a few additional
|
| 45 |
+
security checks, such as HTTPS and state checking.
|
| 46 |
+
|
| 47 |
+
Some of these methods require further implementation only provided by the
|
| 48 |
+
specific purpose clients such as
|
| 49 |
+
:py:class:`oauthlib.oauth2.MobileApplicationClient` and thus you should always
|
| 50 |
+
seek to use the client class matching the OAuth workflow you need. For
|
| 51 |
+
Python, this is usually :py:class:`oauthlib.oauth2.WebApplicationClient`.
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
refresh_token_key = 'refresh_token'
|
| 55 |
+
|
| 56 |
+
def __init__(self, client_id,
|
| 57 |
+
default_token_placement=AUTH_HEADER,
|
| 58 |
+
token_type='Bearer',
|
| 59 |
+
access_token=None,
|
| 60 |
+
refresh_token=None,
|
| 61 |
+
mac_key=None,
|
| 62 |
+
mac_algorithm=None,
|
| 63 |
+
token=None,
|
| 64 |
+
scope=None,
|
| 65 |
+
state=None,
|
| 66 |
+
redirect_url=None,
|
| 67 |
+
state_generator=generate_token,
|
| 68 |
+
code_verifier=None,
|
| 69 |
+
code_challenge=None,
|
| 70 |
+
code_challenge_method=None,
|
| 71 |
+
**kwargs):
|
| 72 |
+
"""Initialize a client with commonly used attributes.
|
| 73 |
+
|
| 74 |
+
:param client_id: Client identifier given by the OAuth provider upon
|
| 75 |
+
registration.
|
| 76 |
+
|
| 77 |
+
:param default_token_placement: Tokens can be supplied in the Authorization
|
| 78 |
+
header (default), the URL query component (``query``) or the request
|
| 79 |
+
body (``body``).
|
| 80 |
+
|
| 81 |
+
:param token_type: OAuth 2 token type. Defaults to Bearer. Change this
|
| 82 |
+
if you specify the ``access_token`` parameter and know it is of a
|
| 83 |
+
different token type, such as a MAC, JWT or SAML token. Can
|
| 84 |
+
also be supplied as ``token_type`` inside the ``token`` dict parameter.
|
| 85 |
+
|
| 86 |
+
:param access_token: An access token (string) used to authenticate
|
| 87 |
+
requests to protected resources. Can also be supplied inside the
|
| 88 |
+
``token`` dict parameter.
|
| 89 |
+
|
| 90 |
+
:param refresh_token: A refresh token (string) used to refresh expired
|
| 91 |
+
tokens. Can also be supplied inside the ``token`` dict parameter.
|
| 92 |
+
|
| 93 |
+
:param mac_key: Encryption key used with MAC tokens.
|
| 94 |
+
|
| 95 |
+
:param mac_algorithm: Hashing algorithm for MAC tokens.
|
| 96 |
+
|
| 97 |
+
:param token: A dict of token attributes such as ``access_token``,
|
| 98 |
+
``token_type`` and ``expires_at``.
|
| 99 |
+
|
| 100 |
+
:param scope: A list of default scopes to request authorization for.
|
| 101 |
+
|
| 102 |
+
:param state: A CSRF protection string used during authorization.
|
| 103 |
+
|
| 104 |
+
:param redirect_url: The redirection endpoint on the client side to which
|
| 105 |
+
the user returns after authorization.
|
| 106 |
+
|
| 107 |
+
:param state_generator: A no argument state generation callable. Defaults
|
| 108 |
+
to :py:meth:`oauthlib.common.generate_token`.
|
| 109 |
+
|
| 110 |
+
:param code_verifier: PKCE parameter. A cryptographically random string that is used to correlate the
|
| 111 |
+
authorization request to the token request.
|
| 112 |
+
|
| 113 |
+
:param code_challenge: PKCE parameter. A challenge derived from the code verifier that is sent in the
|
| 114 |
+
authorization request, to be verified against later.
|
| 115 |
+
|
| 116 |
+
:param code_challenge_method: PKCE parameter. A method that was used to derive code challenge.
|
| 117 |
+
Defaults to "plain" if not present in the request.
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
self.client_id = client_id
|
| 121 |
+
self.default_token_placement = default_token_placement
|
| 122 |
+
self.token_type = token_type
|
| 123 |
+
self.access_token = access_token
|
| 124 |
+
self.refresh_token = refresh_token
|
| 125 |
+
self.mac_key = mac_key
|
| 126 |
+
self.mac_algorithm = mac_algorithm
|
| 127 |
+
self.token = token or {}
|
| 128 |
+
self.scope = scope
|
| 129 |
+
self.state_generator = state_generator
|
| 130 |
+
self.state = state
|
| 131 |
+
self.redirect_url = redirect_url
|
| 132 |
+
self.code_verifier = code_verifier
|
| 133 |
+
self.code_challenge = code_challenge
|
| 134 |
+
self.code_challenge_method = code_challenge_method
|
| 135 |
+
self.code = None
|
| 136 |
+
self.expires_in = None
|
| 137 |
+
self._expires_at = None
|
| 138 |
+
self.populate_token_attributes(self.token)
|
| 139 |
+
|
| 140 |
+
@property
|
| 141 |
+
def token_types(self):
|
| 142 |
+
"""Supported token types and their respective methods
|
| 143 |
+
|
| 144 |
+
Additional tokens can be supported by extending this dictionary.
|
| 145 |
+
|
| 146 |
+
The Bearer token spec is stable and safe to use.
|
| 147 |
+
|
| 148 |
+
The MAC token spec is not yet stable and support for MAC tokens
|
| 149 |
+
is experimental and currently matching version 00 of the spec.
|
| 150 |
+
"""
|
| 151 |
+
return {
|
| 152 |
+
'Bearer': self._add_bearer_token,
|
| 153 |
+
'MAC': self._add_mac_token
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
def prepare_request_uri(self, *args, **kwargs):
|
| 157 |
+
"""Abstract method used to create request URIs."""
|
| 158 |
+
raise NotImplementedError("Must be implemented by inheriting classes.")
|
| 159 |
+
|
| 160 |
+
def prepare_request_body(self, *args, **kwargs):
|
| 161 |
+
"""Abstract method used to create request bodies."""
|
| 162 |
+
raise NotImplementedError("Must be implemented by inheriting classes.")
|
| 163 |
+
|
| 164 |
+
def parse_request_uri_response(self, *args, **kwargs):
|
| 165 |
+
"""Abstract method used to parse redirection responses."""
|
| 166 |
+
raise NotImplementedError("Must be implemented by inheriting classes.")
|
| 167 |
+
|
| 168 |
+
def add_token(self, uri, http_method='GET', body=None, headers=None,
|
| 169 |
+
token_placement=None, **kwargs):
|
| 170 |
+
"""Add token to the request uri, body or authorization header.
|
| 171 |
+
|
| 172 |
+
The access token type provides the client with the information
|
| 173 |
+
required to successfully utilize the access token to make a protected
|
| 174 |
+
resource request (along with type-specific attributes). The client
|
| 175 |
+
MUST NOT use an access token if it does not understand the token
|
| 176 |
+
type.
|
| 177 |
+
|
| 178 |
+
For example, the "bearer" token type defined in
|
| 179 |
+
[`I-D.ietf-oauth-v2-bearer`_] is utilized by simply including the access
|
| 180 |
+
token string in the request:
|
| 181 |
+
|
| 182 |
+
.. code-block:: http
|
| 183 |
+
|
| 184 |
+
GET /resource/1 HTTP/1.1
|
| 185 |
+
Host: example.com
|
| 186 |
+
Authorization: Bearer mF_9.B5f-4.1JqM
|
| 187 |
+
|
| 188 |
+
while the "mac" token type defined in [`I-D.ietf-oauth-v2-http-mac`_] is
|
| 189 |
+
utilized by issuing a MAC key together with the access token which is
|
| 190 |
+
used to sign certain components of the HTTP requests:
|
| 191 |
+
|
| 192 |
+
.. code-block:: http
|
| 193 |
+
|
| 194 |
+
GET /resource/1 HTTP/1.1
|
| 195 |
+
Host: example.com
|
| 196 |
+
Authorization: MAC id="h480djs93hd8",
|
| 197 |
+
nonce="274312:dj83hs9s",
|
| 198 |
+
mac="kDZvddkndxvhGRXZhvuDjEWhGeE="
|
| 199 |
+
|
| 200 |
+
.. _`I-D.ietf-oauth-v2-bearer`: https://tools.ietf.org/html/rfc6749#section-12.2
|
| 201 |
+
.. _`I-D.ietf-oauth-v2-http-mac`: https://tools.ietf.org/html/rfc6749#section-12.2
|
| 202 |
+
"""
|
| 203 |
+
if not is_secure_transport(uri):
|
| 204 |
+
raise InsecureTransportError()
|
| 205 |
+
|
| 206 |
+
token_placement = token_placement or self.default_token_placement
|
| 207 |
+
|
| 208 |
+
case_insensitive_token_types = {
|
| 209 |
+
k.lower(): v for k, v in self.token_types.items()}
|
| 210 |
+
if not self.token_type.lower() in case_insensitive_token_types:
|
| 211 |
+
raise ValueError("Unsupported token type: %s" % self.token_type)
|
| 212 |
+
|
| 213 |
+
if not (self.access_token or self.token.get('access_token')):
|
| 214 |
+
raise ValueError("Missing access token.")
|
| 215 |
+
|
| 216 |
+
if self._expires_at and self._expires_at < time.time():
|
| 217 |
+
raise TokenExpiredError()
|
| 218 |
+
|
| 219 |
+
return case_insensitive_token_types[self.token_type.lower()](uri, http_method, body,
|
| 220 |
+
headers, token_placement, **kwargs)
|
| 221 |
+
|
| 222 |
+
def prepare_authorization_request(self, authorization_url, state=None,
|
| 223 |
+
redirect_url=None, scope=None, **kwargs):
|
| 224 |
+
"""Prepare the authorization request.
|
| 225 |
+
|
| 226 |
+
This is the first step in many OAuth flows in which the user is
|
| 227 |
+
redirected to a certain authorization URL. This method adds
|
| 228 |
+
required parameters to the authorization URL.
|
| 229 |
+
|
| 230 |
+
:param authorization_url: Provider authorization endpoint URL.
|
| 231 |
+
:param state: CSRF protection string. Will be automatically created if
|
| 232 |
+
not provided. The generated state is available via the ``state``
|
| 233 |
+
attribute. Clients should verify that the state is unchanged and
|
| 234 |
+
present in the authorization response. This verification is done
|
| 235 |
+
automatically if using the ``authorization_response`` parameter
|
| 236 |
+
with ``prepare_token_request``.
|
| 237 |
+
:param redirect_url: Redirect URL to which the user will be returned
|
| 238 |
+
after authorization. Must be provided unless previously setup with
|
| 239 |
+
the provider. If provided then it must also be provided in the
|
| 240 |
+
token request.
|
| 241 |
+
:param scope: List of scopes to request. Must be equal to
|
| 242 |
+
or a subset of the scopes granted when obtaining the refresh
|
| 243 |
+
token. If none is provided, the ones provided in the constructor are
|
| 244 |
+
used.
|
| 245 |
+
:param kwargs: Additional parameters to included in the request.
|
| 246 |
+
:returns: The prepared request tuple with (url, headers, body).
|
| 247 |
+
"""
|
| 248 |
+
if not is_secure_transport(authorization_url):
|
| 249 |
+
raise InsecureTransportError()
|
| 250 |
+
|
| 251 |
+
self.state = state or self.state_generator()
|
| 252 |
+
self.redirect_url = redirect_url or self.redirect_url
|
| 253 |
+
# do not assign scope to self automatically anymore
|
| 254 |
+
scope = self.scope if scope is None else scope
|
| 255 |
+
auth_url = self.prepare_request_uri(
|
| 256 |
+
authorization_url, redirect_uri=self.redirect_url,
|
| 257 |
+
scope=scope, state=self.state, **kwargs)
|
| 258 |
+
return auth_url, FORM_ENC_HEADERS, ''
|
| 259 |
+
|
| 260 |
+
def prepare_token_request(self, token_url, authorization_response=None,
|
| 261 |
+
redirect_url=None, state=None, body='', **kwargs):
|
| 262 |
+
"""Prepare a token creation request.
|
| 263 |
+
|
| 264 |
+
Note that these requests usually require client authentication, either
|
| 265 |
+
by including client_id or a set of provider specific authentication
|
| 266 |
+
credentials.
|
| 267 |
+
|
| 268 |
+
:param token_url: Provider token creation endpoint URL.
|
| 269 |
+
:param authorization_response: The full redirection URL string, i.e.
|
| 270 |
+
the location to which the user was redirected after successful
|
| 271 |
+
authorization. Used to mine credentials needed to obtain a token
|
| 272 |
+
in this step, such as authorization code.
|
| 273 |
+
:param redirect_url: The redirect_url supplied with the authorization
|
| 274 |
+
request (if there was one).
|
| 275 |
+
:param state:
|
| 276 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 277 |
+
into. This may contain extra parameters. Default ''.
|
| 278 |
+
:param kwargs: Additional parameters to included in the request.
|
| 279 |
+
:returns: The prepared request tuple with (url, headers, body).
|
| 280 |
+
"""
|
| 281 |
+
if not is_secure_transport(token_url):
|
| 282 |
+
raise InsecureTransportError()
|
| 283 |
+
|
| 284 |
+
state = state or self.state
|
| 285 |
+
if authorization_response:
|
| 286 |
+
self.parse_request_uri_response(
|
| 287 |
+
authorization_response, state=state)
|
| 288 |
+
self.redirect_url = redirect_url or self.redirect_url
|
| 289 |
+
body = self.prepare_request_body(body=body,
|
| 290 |
+
redirect_uri=self.redirect_url, **kwargs)
|
| 291 |
+
|
| 292 |
+
return token_url, FORM_ENC_HEADERS, body
|
| 293 |
+
|
| 294 |
+
def prepare_refresh_token_request(self, token_url, refresh_token=None,
|
| 295 |
+
body='', scope=None, **kwargs):
|
| 296 |
+
"""Prepare an access token refresh request.
|
| 297 |
+
|
| 298 |
+
Expired access tokens can be replaced by new access tokens without
|
| 299 |
+
going through the OAuth dance if the client obtained a refresh token.
|
| 300 |
+
This refresh token and authentication credentials can be used to
|
| 301 |
+
obtain a new access token, and possibly a new refresh token.
|
| 302 |
+
|
| 303 |
+
:param token_url: Provider token refresh endpoint URL.
|
| 304 |
+
:param refresh_token: Refresh token string.
|
| 305 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 306 |
+
into. This may contain extra parameters. Default ''.
|
| 307 |
+
:param scope: List of scopes to request. Must be equal to
|
| 308 |
+
or a subset of the scopes granted when obtaining the refresh
|
| 309 |
+
token. If none is provided, the ones provided in the constructor are
|
| 310 |
+
used.
|
| 311 |
+
:param kwargs: Additional parameters to included in the request.
|
| 312 |
+
:returns: The prepared request tuple with (url, headers, body).
|
| 313 |
+
"""
|
| 314 |
+
if not is_secure_transport(token_url):
|
| 315 |
+
raise InsecureTransportError()
|
| 316 |
+
|
| 317 |
+
# do not assign scope to self automatically anymore
|
| 318 |
+
scope = self.scope if scope is None else scope
|
| 319 |
+
body = self.prepare_refresh_body(body=body,
|
| 320 |
+
refresh_token=refresh_token, scope=scope, **kwargs)
|
| 321 |
+
return token_url, FORM_ENC_HEADERS, body
|
| 322 |
+
|
| 323 |
+
def prepare_token_revocation_request(self, revocation_url, token,
|
| 324 |
+
token_type_hint="access_token", body='', callback=None, **kwargs):
|
| 325 |
+
"""Prepare a token revocation request.
|
| 326 |
+
|
| 327 |
+
:param revocation_url: Provider token revocation endpoint URL.
|
| 328 |
+
:param token: The access or refresh token to be revoked (string).
|
| 329 |
+
:param token_type_hint: ``"access_token"`` (default) or
|
| 330 |
+
``"refresh_token"``. This is optional and if you wish to not pass it you
|
| 331 |
+
must provide ``token_type_hint=None``.
|
| 332 |
+
:param body:
|
| 333 |
+
:param callback: A jsonp callback such as ``package.callback`` to be invoked
|
| 334 |
+
upon receiving the response. Not that it should not include a () suffix.
|
| 335 |
+
:param kwargs: Additional parameters to included in the request.
|
| 336 |
+
:returns: The prepared request tuple with (url, headers, body).
|
| 337 |
+
|
| 338 |
+
Note that JSONP request may use GET requests as the parameters will
|
| 339 |
+
be added to the request URL query as opposed to the request body.
|
| 340 |
+
|
| 341 |
+
An example of a revocation request
|
| 342 |
+
|
| 343 |
+
.. code-block:: http
|
| 344 |
+
|
| 345 |
+
POST /revoke HTTP/1.1
|
| 346 |
+
Host: server.example.com
|
| 347 |
+
Content-Type: application/x-www-form-urlencoded
|
| 348 |
+
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
|
| 349 |
+
|
| 350 |
+
token=45ghiukldjahdnhzdauz&token_type_hint=refresh_token
|
| 351 |
+
|
| 352 |
+
An example of a jsonp revocation request
|
| 353 |
+
|
| 354 |
+
.. code-block:: http
|
| 355 |
+
|
| 356 |
+
GET /revoke?token=agabcdefddddafdd&callback=package.myCallback HTTP/1.1
|
| 357 |
+
Host: server.example.com
|
| 358 |
+
Content-Type: application/x-www-form-urlencoded
|
| 359 |
+
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
|
| 360 |
+
|
| 361 |
+
and an error response
|
| 362 |
+
|
| 363 |
+
.. code-block:: javascript
|
| 364 |
+
|
| 365 |
+
package.myCallback({"error":"unsupported_token_type"});
|
| 366 |
+
|
| 367 |
+
Note that these requests usually require client credentials, client_id in
|
| 368 |
+
the case for public clients and provider specific authentication
|
| 369 |
+
credentials for confidential clients.
|
| 370 |
+
"""
|
| 371 |
+
if not is_secure_transport(revocation_url):
|
| 372 |
+
raise InsecureTransportError()
|
| 373 |
+
|
| 374 |
+
return prepare_token_revocation_request(revocation_url, token,
|
| 375 |
+
token_type_hint=token_type_hint, body=body, callback=callback,
|
| 376 |
+
**kwargs)
|
| 377 |
+
|
| 378 |
+
def parse_request_body_response(self, body, scope=None, **kwargs):
|
| 379 |
+
"""Parse the JSON response body.
|
| 380 |
+
|
| 381 |
+
If the access token request is valid and authorized, the
|
| 382 |
+
authorization server issues an access token as described in
|
| 383 |
+
`Section 5.1`_. A refresh token SHOULD NOT be included. If the request
|
| 384 |
+
failed client authentication or is invalid, the authorization server
|
| 385 |
+
returns an error response as described in `Section 5.2`_.
|
| 386 |
+
|
| 387 |
+
:param body: The response body from the token request.
|
| 388 |
+
:param scope: Scopes originally requested. If none is provided, the ones
|
| 389 |
+
provided in the constructor are used.
|
| 390 |
+
:return: Dictionary of token parameters.
|
| 391 |
+
:raises: Warning if scope has changed. :py:class:`oauthlib.oauth2.errors.OAuth2Error`
|
| 392 |
+
if response is invalid.
|
| 393 |
+
|
| 394 |
+
These response are json encoded and could easily be parsed without
|
| 395 |
+
the assistance of OAuthLib. However, there are a few subtle issues
|
| 396 |
+
to be aware of regarding the response which are helpfully addressed
|
| 397 |
+
through the raising of various errors.
|
| 398 |
+
|
| 399 |
+
A successful response should always contain
|
| 400 |
+
|
| 401 |
+
**access_token**
|
| 402 |
+
The access token issued by the authorization server. Often
|
| 403 |
+
a random string.
|
| 404 |
+
|
| 405 |
+
**token_type**
|
| 406 |
+
The type of the token issued as described in `Section 7.1`_.
|
| 407 |
+
Commonly ``Bearer``.
|
| 408 |
+
|
| 409 |
+
While it is not mandated it is recommended that the provider include
|
| 410 |
+
|
| 411 |
+
**expires_in**
|
| 412 |
+
The lifetime in seconds of the access token. For
|
| 413 |
+
example, the value "3600" denotes that the access token will
|
| 414 |
+
expire in one hour from the time the response was generated.
|
| 415 |
+
If omitted, the authorization server SHOULD provide the
|
| 416 |
+
expiration time via other means or document the default value.
|
| 417 |
+
|
| 418 |
+
**scope**
|
| 419 |
+
Providers may supply this in all responses but are required to only
|
| 420 |
+
if it has changed since the authorization request.
|
| 421 |
+
|
| 422 |
+
.. _`Section 5.1`: https://tools.ietf.org/html/rfc6749#section-5.1
|
| 423 |
+
.. _`Section 5.2`: https://tools.ietf.org/html/rfc6749#section-5.2
|
| 424 |
+
.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
|
| 425 |
+
"""
|
| 426 |
+
scope = self.scope if scope is None else scope
|
| 427 |
+
self.token = parse_token_response(body, scope=scope)
|
| 428 |
+
self.populate_token_attributes(self.token)
|
| 429 |
+
return self.token
|
| 430 |
+
|
| 431 |
+
def prepare_refresh_body(self, body='', refresh_token=None, scope=None, **kwargs):
|
| 432 |
+
"""Prepare an access token request, using a refresh token.
|
| 433 |
+
|
| 434 |
+
If the authorization server issued a refresh token to the client, the
|
| 435 |
+
client makes a refresh request to the token endpoint by adding the
|
| 436 |
+
following parameters using the `application/x-www-form-urlencoded`
|
| 437 |
+
format in the HTTP request entity-body:
|
| 438 |
+
|
| 439 |
+
:param refresh_token: REQUIRED. The refresh token issued to the client.
|
| 440 |
+
:param scope: OPTIONAL. The scope of the access request as described by
|
| 441 |
+
Section 3.3. The requested scope MUST NOT include any scope
|
| 442 |
+
not originally granted by the resource owner, and if omitted is
|
| 443 |
+
treated as equal to the scope originally granted by the
|
| 444 |
+
resource owner. Note that if none is provided, the ones provided
|
| 445 |
+
in the constructor are used if any.
|
| 446 |
+
"""
|
| 447 |
+
refresh_token = refresh_token or self.refresh_token
|
| 448 |
+
scope = self.scope if scope is None else scope
|
| 449 |
+
return prepare_token_request(self.refresh_token_key, body=body, scope=scope,
|
| 450 |
+
refresh_token=refresh_token, **kwargs)
|
| 451 |
+
|
| 452 |
+
def _add_bearer_token(self, uri, http_method='GET', body=None,
|
| 453 |
+
headers=None, token_placement=None):
|
| 454 |
+
"""Add a bearer token to the request uri, body or authorization header."""
|
| 455 |
+
if token_placement == AUTH_HEADER:
|
| 456 |
+
headers = tokens.prepare_bearer_headers(self.access_token, headers)
|
| 457 |
+
|
| 458 |
+
elif token_placement == URI_QUERY:
|
| 459 |
+
uri = tokens.prepare_bearer_uri(self.access_token, uri)
|
| 460 |
+
|
| 461 |
+
elif token_placement == BODY:
|
| 462 |
+
body = tokens.prepare_bearer_body(self.access_token, body)
|
| 463 |
+
|
| 464 |
+
else:
|
| 465 |
+
raise ValueError("Invalid token placement.")
|
| 466 |
+
return uri, headers, body
|
| 467 |
+
|
| 468 |
+
def create_code_verifier(self, length):
|
| 469 |
+
"""Create PKCE **code_verifier** used in computing **code_challenge**.
|
| 470 |
+
See `RFC7636 Section 4.1`_
|
| 471 |
+
|
| 472 |
+
:param length: REQUIRED. The length of the code_verifier.
|
| 473 |
+
|
| 474 |
+
The client first creates a code verifier, "code_verifier", for each
|
| 475 |
+
OAuth 2.0 [RFC6749] Authorization Request, in the following manner:
|
| 476 |
+
|
| 477 |
+
.. code-block:: text
|
| 478 |
+
|
| 479 |
+
code_verifier = high-entropy cryptographic random STRING using the
|
| 480 |
+
unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
|
| 481 |
+
from Section 2.3 of [RFC3986], with a minimum length of 43 characters
|
| 482 |
+
and a maximum length of 128 characters.
|
| 483 |
+
|
| 484 |
+
.. _`RFC7636 Section 4.1`: https://tools.ietf.org/html/rfc7636#section-4.1
|
| 485 |
+
"""
|
| 486 |
+
code_verifier = None
|
| 487 |
+
|
| 488 |
+
if not length >= 43:
|
| 489 |
+
raise ValueError("Length must be greater than or equal to 43")
|
| 490 |
+
|
| 491 |
+
if not length <= 128:
|
| 492 |
+
raise ValueError("Length must be less than or equal to 128")
|
| 493 |
+
|
| 494 |
+
allowed_characters = re.compile('^[A-Zaa-z0-9-._~]')
|
| 495 |
+
code_verifier = secrets.token_urlsafe(length)
|
| 496 |
+
|
| 497 |
+
if not re.search(allowed_characters, code_verifier):
|
| 498 |
+
raise ValueError("code_verifier contains invalid characters")
|
| 499 |
+
|
| 500 |
+
self.code_verifier = code_verifier
|
| 501 |
+
|
| 502 |
+
return code_verifier
|
| 503 |
+
|
| 504 |
+
def create_code_challenge(self, code_verifier, code_challenge_method=None):
|
| 505 |
+
"""Create PKCE **code_challenge** derived from the **code_verifier**.
|
| 506 |
+
See `RFC7636 Section 4.2`_
|
| 507 |
+
|
| 508 |
+
:param code_verifier: REQUIRED. The **code_verifier** generated from `create_code_verifier()`.
|
| 509 |
+
:param code_challenge_method: OPTIONAL. The method used to derive the **code_challenge**. Acceptable values include `S256`. DEFAULT is `plain`.
|
| 510 |
+
|
| 511 |
+
The client then creates a code challenge derived from the code
|
| 512 |
+
verifier by using one of the following transformations on the code
|
| 513 |
+
verifier::
|
| 514 |
+
|
| 515 |
+
plain
|
| 516 |
+
code_challenge = code_verifier
|
| 517 |
+
S256
|
| 518 |
+
code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
|
| 519 |
+
|
| 520 |
+
If the client is capable of using `S256`, it MUST use `S256`, as
|
| 521 |
+
`S256` is Mandatory To Implement (MTI) on the server. Clients are
|
| 522 |
+
permitted to use `plain` only if they cannot support `S256` for some
|
| 523 |
+
technical reason and know via out-of-band configuration that the
|
| 524 |
+
server supports `plain`.
|
| 525 |
+
|
| 526 |
+
The plain transformation is for compatibility with existing
|
| 527 |
+
deployments and for constrained environments that can't use the S256 transformation.
|
| 528 |
+
|
| 529 |
+
.. _`RFC7636 Section 4.2`: https://tools.ietf.org/html/rfc7636#section-4.2
|
| 530 |
+
"""
|
| 531 |
+
code_challenge = None
|
| 532 |
+
|
| 533 |
+
if code_verifier == None:
|
| 534 |
+
raise ValueError("Invalid code_verifier")
|
| 535 |
+
|
| 536 |
+
if code_challenge_method == None:
|
| 537 |
+
code_challenge_method = "plain"
|
| 538 |
+
self.code_challenge_method = code_challenge_method
|
| 539 |
+
code_challenge = code_verifier
|
| 540 |
+
self.code_challenge = code_challenge
|
| 541 |
+
|
| 542 |
+
if code_challenge_method == "S256":
|
| 543 |
+
h = hashlib.sha256()
|
| 544 |
+
h.update(code_verifier.encode(encoding='ascii'))
|
| 545 |
+
sha256_val = h.digest()
|
| 546 |
+
code_challenge = bytes.decode(base64.urlsafe_b64encode(sha256_val))
|
| 547 |
+
# replace '+' with '-', '/' with '_', and remove trailing '='
|
| 548 |
+
code_challenge = code_challenge.replace("+", "-").replace("/", "_").replace("=", "")
|
| 549 |
+
self.code_challenge = code_challenge
|
| 550 |
+
|
| 551 |
+
return code_challenge
|
| 552 |
+
|
| 553 |
+
def _add_mac_token(self, uri, http_method='GET', body=None,
|
| 554 |
+
headers=None, token_placement=AUTH_HEADER, ext=None, **kwargs):
|
| 555 |
+
"""Add a MAC token to the request authorization header.
|
| 556 |
+
|
| 557 |
+
Warning: MAC token support is experimental as the spec is not yet stable.
|
| 558 |
+
"""
|
| 559 |
+
if token_placement != AUTH_HEADER:
|
| 560 |
+
raise ValueError("Invalid token placement.")
|
| 561 |
+
|
| 562 |
+
headers = tokens.prepare_mac_header(self.access_token, uri,
|
| 563 |
+
self.mac_key, http_method, headers=headers, body=body, ext=ext,
|
| 564 |
+
hash_algorithm=self.mac_algorithm, **kwargs)
|
| 565 |
+
return uri, headers, body
|
| 566 |
+
|
| 567 |
+
def _populate_attributes(self, response):
|
| 568 |
+
warnings.warn("Please switch to the public method "
|
| 569 |
+
"populate_token_attributes.", DeprecationWarning)
|
| 570 |
+
return self.populate_token_attributes(response)
|
| 571 |
+
|
| 572 |
+
def populate_code_attributes(self, response):
|
| 573 |
+
"""Add attributes from an auth code response to self."""
|
| 574 |
+
|
| 575 |
+
if 'code' in response:
|
| 576 |
+
self.code = response.get('code')
|
| 577 |
+
|
| 578 |
+
def populate_token_attributes(self, response):
|
| 579 |
+
"""Add attributes from a token exchange response to self."""
|
| 580 |
+
|
| 581 |
+
if 'access_token' in response:
|
| 582 |
+
self.access_token = response.get('access_token')
|
| 583 |
+
|
| 584 |
+
if 'refresh_token' in response:
|
| 585 |
+
self.refresh_token = response.get('refresh_token')
|
| 586 |
+
|
| 587 |
+
if 'token_type' in response:
|
| 588 |
+
self.token_type = response.get('token_type')
|
| 589 |
+
|
| 590 |
+
if 'expires_in' in response:
|
| 591 |
+
self.expires_in = response.get('expires_in')
|
| 592 |
+
self._expires_at = time.time() + int(self.expires_in)
|
| 593 |
+
|
| 594 |
+
if 'expires_at' in response:
|
| 595 |
+
try:
|
| 596 |
+
self._expires_at = int(response.get('expires_at'))
|
| 597 |
+
except:
|
| 598 |
+
self._expires_at = None
|
| 599 |
+
|
| 600 |
+
if 'mac_key' in response:
|
| 601 |
+
self.mac_key = response.get('mac_key')
|
| 602 |
+
|
| 603 |
+
if 'mac_algorithm' in response:
|
| 604 |
+
self.mac_algorithm = response.get('mac_algorithm')
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/legacy_application.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
from ..parameters import prepare_token_request
|
| 10 |
+
from .base import Client
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class LegacyApplicationClient(Client):
|
| 14 |
+
|
| 15 |
+
"""A public client using the resource owner password and username directly.
|
| 16 |
+
|
| 17 |
+
The resource owner password credentials grant type is suitable in
|
| 18 |
+
cases where the resource owner has a trust relationship with the
|
| 19 |
+
client, such as the device operating system or a highly privileged
|
| 20 |
+
application. The authorization server should take special care when
|
| 21 |
+
enabling this grant type, and only allow it when other flows are not
|
| 22 |
+
viable.
|
| 23 |
+
|
| 24 |
+
The grant type is suitable for clients capable of obtaining the
|
| 25 |
+
resource owner's credentials (username and password, typically using
|
| 26 |
+
an interactive form). It is also used to migrate existing clients
|
| 27 |
+
using direct authentication schemes such as HTTP Basic or Digest
|
| 28 |
+
authentication to OAuth by converting the stored credentials to an
|
| 29 |
+
access token.
|
| 30 |
+
|
| 31 |
+
The method through which the client obtains the resource owner
|
| 32 |
+
credentials is beyond the scope of this specification. The client
|
| 33 |
+
MUST discard the credentials once an access token has been obtained.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
grant_type = 'password'
|
| 37 |
+
|
| 38 |
+
def __init__(self, client_id, **kwargs):
|
| 39 |
+
super().__init__(client_id, **kwargs)
|
| 40 |
+
|
| 41 |
+
def prepare_request_body(self, username, password, body='', scope=None,
|
| 42 |
+
include_client_id=False, **kwargs):
|
| 43 |
+
"""Add the resource owner password and username to the request body.
|
| 44 |
+
|
| 45 |
+
The client makes a request to the token endpoint by adding the
|
| 46 |
+
following parameters using the "application/x-www-form-urlencoded"
|
| 47 |
+
format per `Appendix B`_ in the HTTP request entity-body:
|
| 48 |
+
|
| 49 |
+
:param username: The resource owner username.
|
| 50 |
+
:param password: The resource owner password.
|
| 51 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 52 |
+
into. This may contain extra parameters. Default ''.
|
| 53 |
+
:param scope: The scope of the access request as described by
|
| 54 |
+
`Section 3.3`_.
|
| 55 |
+
:param include_client_id: `True` to send the `client_id` in the
|
| 56 |
+
body of the upstream request. This is required
|
| 57 |
+
if the client is not authenticating with the
|
| 58 |
+
authorization server as described in
|
| 59 |
+
`Section 3.2.1`_. False otherwise (default).
|
| 60 |
+
:type include_client_id: Boolean
|
| 61 |
+
:param kwargs: Extra credentials to include in the token request.
|
| 62 |
+
|
| 63 |
+
If the client type is confidential or the client was issued client
|
| 64 |
+
credentials (or assigned other authentication requirements), the
|
| 65 |
+
client MUST authenticate with the authorization server as described
|
| 66 |
+
in `Section 3.2.1`_.
|
| 67 |
+
|
| 68 |
+
The prepared body will include all provided credentials as well as
|
| 69 |
+
the ``grant_type`` parameter set to ``password``::
|
| 70 |
+
|
| 71 |
+
>>> from oauthlib.oauth2 import LegacyApplicationClient
|
| 72 |
+
>>> client = LegacyApplicationClient('your_id')
|
| 73 |
+
>>> client.prepare_request_body(username='foo', password='bar', scope=['hello', 'world'])
|
| 74 |
+
'grant_type=password&username=foo&scope=hello+world&password=bar'
|
| 75 |
+
|
| 76 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 77 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 78 |
+
.. _`Section 3.2.1`: https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 79 |
+
"""
|
| 80 |
+
kwargs['client_id'] = self.client_id
|
| 81 |
+
kwargs['include_client_id'] = include_client_id
|
| 82 |
+
scope = self.scope if scope is None else scope
|
| 83 |
+
return prepare_token_request(self.grant_type, body=body, username=username,
|
| 84 |
+
password=password, scope=scope, **kwargs)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/mobile_application.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
from ..parameters import parse_implicit_response, prepare_grant_uri
|
| 10 |
+
from .base import Client
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MobileApplicationClient(Client):
|
| 14 |
+
|
| 15 |
+
"""A public client utilizing the implicit code grant workflow.
|
| 16 |
+
|
| 17 |
+
A user-agent-based application is a public client in which the
|
| 18 |
+
client code is downloaded from a web server and executes within a
|
| 19 |
+
user-agent (e.g. web browser) on the device used by the resource
|
| 20 |
+
owner. Protocol data and credentials are easily accessible (and
|
| 21 |
+
often visible) to the resource owner. Since such applications
|
| 22 |
+
reside within the user-agent, they can make seamless use of the
|
| 23 |
+
user-agent capabilities when requesting authorization.
|
| 24 |
+
|
| 25 |
+
The implicit grant type is used to obtain access tokens (it does not
|
| 26 |
+
support the issuance of refresh tokens) and is optimized for public
|
| 27 |
+
clients known to operate a particular redirection URI. These clients
|
| 28 |
+
are typically implemented in a browser using a scripting language
|
| 29 |
+
such as JavaScript.
|
| 30 |
+
|
| 31 |
+
As a redirection-based flow, the client must be capable of
|
| 32 |
+
interacting with the resource owner's user-agent (typically a web
|
| 33 |
+
browser) and capable of receiving incoming requests (via redirection)
|
| 34 |
+
from the authorization server.
|
| 35 |
+
|
| 36 |
+
Unlike the authorization code grant type in which the client makes
|
| 37 |
+
separate requests for authorization and access token, the client
|
| 38 |
+
receives the access token as the result of the authorization request.
|
| 39 |
+
|
| 40 |
+
The implicit grant type does not include client authentication, and
|
| 41 |
+
relies on the presence of the resource owner and the registration of
|
| 42 |
+
the redirection URI. Because the access token is encoded into the
|
| 43 |
+
redirection URI, it may be exposed to the resource owner and other
|
| 44 |
+
applications residing on the same device.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
response_type = 'token'
|
| 48 |
+
|
| 49 |
+
def prepare_request_uri(self, uri, redirect_uri=None, scope=None,
|
| 50 |
+
state=None, **kwargs):
|
| 51 |
+
"""Prepare the implicit grant request URI.
|
| 52 |
+
|
| 53 |
+
The client constructs the request URI by adding the following
|
| 54 |
+
parameters to the query component of the authorization endpoint URI
|
| 55 |
+
using the "application/x-www-form-urlencoded" format, per `Appendix B`_:
|
| 56 |
+
|
| 57 |
+
:param redirect_uri: OPTIONAL. The redirect URI must be an absolute URI
|
| 58 |
+
and it should have been registered with the OAuth
|
| 59 |
+
provider prior to use. As described in `Section 3.1.2`_.
|
| 60 |
+
|
| 61 |
+
:param scope: OPTIONAL. The scope of the access request as described by
|
| 62 |
+
Section 3.3`_. These may be any string but are commonly
|
| 63 |
+
URIs or various categories such as ``videos`` or ``documents``.
|
| 64 |
+
|
| 65 |
+
:param state: RECOMMENDED. An opaque value used by the client to maintain
|
| 66 |
+
state between the request and callback. The authorization
|
| 67 |
+
server includes this value when redirecting the user-agent back
|
| 68 |
+
to the client. The parameter SHOULD be used for preventing
|
| 69 |
+
cross-site request forgery as described in `Section 10.12`_.
|
| 70 |
+
|
| 71 |
+
:param kwargs: Extra arguments to include in the request URI.
|
| 72 |
+
|
| 73 |
+
In addition to supplied parameters, OAuthLib will append the ``client_id``
|
| 74 |
+
that was provided in the constructor as well as the mandatory ``response_type``
|
| 75 |
+
argument, set to ``token``::
|
| 76 |
+
|
| 77 |
+
>>> from oauthlib.oauth2 import MobileApplicationClient
|
| 78 |
+
>>> client = MobileApplicationClient('your_id')
|
| 79 |
+
>>> client.prepare_request_uri('https://example.com')
|
| 80 |
+
'https://example.com?client_id=your_id&response_type=token'
|
| 81 |
+
>>> client.prepare_request_uri('https://example.com', redirect_uri='https://a.b/callback')
|
| 82 |
+
'https://example.com?client_id=your_id&response_type=token&redirect_uri=https%3A%2F%2Fa.b%2Fcallback'
|
| 83 |
+
>>> client.prepare_request_uri('https://example.com', scope=['profile', 'pictures'])
|
| 84 |
+
'https://example.com?client_id=your_id&response_type=token&scope=profile+pictures'
|
| 85 |
+
>>> client.prepare_request_uri('https://example.com', foo='bar')
|
| 86 |
+
'https://example.com?client_id=your_id&response_type=token&foo=bar'
|
| 87 |
+
|
| 88 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 89 |
+
.. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2
|
| 90 |
+
.. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 91 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 92 |
+
.. _`Section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12
|
| 93 |
+
"""
|
| 94 |
+
scope = self.scope if scope is None else scope
|
| 95 |
+
return prepare_grant_uri(uri, self.client_id, self.response_type,
|
| 96 |
+
redirect_uri=redirect_uri, state=state, scope=scope, **kwargs)
|
| 97 |
+
|
| 98 |
+
def parse_request_uri_response(self, uri, state=None, scope=None):
|
| 99 |
+
"""Parse the response URI fragment.
|
| 100 |
+
|
| 101 |
+
If the resource owner grants the access request, the authorization
|
| 102 |
+
server issues an access token and delivers it to the client by adding
|
| 103 |
+
the following parameters to the fragment component of the redirection
|
| 104 |
+
URI using the "application/x-www-form-urlencoded" format:
|
| 105 |
+
|
| 106 |
+
:param uri: The callback URI that resulted from the user being redirected
|
| 107 |
+
back from the provider to you, the client.
|
| 108 |
+
:param state: The state provided in the authorization request.
|
| 109 |
+
:param scope: The scopes provided in the authorization request.
|
| 110 |
+
:return: Dictionary of token parameters.
|
| 111 |
+
:raises: OAuth2Error if response is invalid.
|
| 112 |
+
|
| 113 |
+
A successful response should always contain
|
| 114 |
+
|
| 115 |
+
**access_token**
|
| 116 |
+
The access token issued by the authorization server. Often
|
| 117 |
+
a random string.
|
| 118 |
+
|
| 119 |
+
**token_type**
|
| 120 |
+
The type of the token issued as described in `Section 7.1`_.
|
| 121 |
+
Commonly ``Bearer``.
|
| 122 |
+
|
| 123 |
+
**state**
|
| 124 |
+
If you provided the state parameter in the authorization phase, then
|
| 125 |
+
the provider is required to include that exact state value in the
|
| 126 |
+
response.
|
| 127 |
+
|
| 128 |
+
While it is not mandated it is recommended that the provider include
|
| 129 |
+
|
| 130 |
+
**expires_in**
|
| 131 |
+
The lifetime in seconds of the access token. For
|
| 132 |
+
example, the value "3600" denotes that the access token will
|
| 133 |
+
expire in one hour from the time the response was generated.
|
| 134 |
+
If omitted, the authorization server SHOULD provide the
|
| 135 |
+
expiration time via other means or document the default value.
|
| 136 |
+
|
| 137 |
+
**scope**
|
| 138 |
+
Providers may supply this in all responses but are required to only
|
| 139 |
+
if it has changed since the authorization request.
|
| 140 |
+
|
| 141 |
+
A few example responses can be seen below::
|
| 142 |
+
|
| 143 |
+
>>> response_uri = 'https://example.com/callback#access_token=sdlfkj452&state=ss345asyht&token_type=Bearer&scope=hello+world'
|
| 144 |
+
>>> from oauthlib.oauth2 import MobileApplicationClient
|
| 145 |
+
>>> client = MobileApplicationClient('your_id')
|
| 146 |
+
>>> client.parse_request_uri_response(response_uri)
|
| 147 |
+
{
|
| 148 |
+
'access_token': 'sdlfkj452',
|
| 149 |
+
'token_type': 'Bearer',
|
| 150 |
+
'state': 'ss345asyht',
|
| 151 |
+
'scope': [u'hello', u'world']
|
| 152 |
+
}
|
| 153 |
+
>>> client.parse_request_uri_response(response_uri, state='other')
|
| 154 |
+
Traceback (most recent call last):
|
| 155 |
+
File "<stdin>", line 1, in <module>
|
| 156 |
+
File "oauthlib/oauth2/rfc6749/__init__.py", line 598, in parse_request_uri_response
|
| 157 |
+
**scope**
|
| 158 |
+
File "oauthlib/oauth2/rfc6749/parameters.py", line 197, in parse_implicit_response
|
| 159 |
+
raise ValueError("Mismatching or missing state in params.")
|
| 160 |
+
ValueError: Mismatching or missing state in params.
|
| 161 |
+
>>> def alert_scope_changed(message, old, new):
|
| 162 |
+
... print(message, old, new)
|
| 163 |
+
...
|
| 164 |
+
>>> oauthlib.signals.scope_changed.connect(alert_scope_changed)
|
| 165 |
+
>>> client.parse_request_body_response(response_body, scope=['other'])
|
| 166 |
+
('Scope has changed from "other" to "hello world".', ['other'], ['hello', 'world'])
|
| 167 |
+
|
| 168 |
+
.. _`Section 7.1`: https://tools.ietf.org/html/rfc6749#section-7.1
|
| 169 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 170 |
+
"""
|
| 171 |
+
scope = self.scope if scope is None else scope
|
| 172 |
+
self.token = parse_implicit_response(uri, state=state, scope=scope)
|
| 173 |
+
self.populate_token_attributes(self.token)
|
| 174 |
+
return self.token
|
evalkit_tf446/lib/python3.10/site-packages/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
import time
|
| 10 |
+
|
| 11 |
+
from oauthlib.common import to_unicode
|
| 12 |
+
|
| 13 |
+
from ..parameters import prepare_token_request
|
| 14 |
+
from .base import Client
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class ServiceApplicationClient(Client):
|
| 18 |
+
"""A public client utilizing the JWT bearer grant.
|
| 19 |
+
|
| 20 |
+
JWT bearer tokes can be used to request an access token when a client
|
| 21 |
+
wishes to utilize an existing trust relationship, expressed through the
|
| 22 |
+
semantics of (and digital signature or keyed message digest calculated
|
| 23 |
+
over) the JWT, without a direct user approval step at the authorization
|
| 24 |
+
server.
|
| 25 |
+
|
| 26 |
+
This grant type does not involve an authorization step. It may be
|
| 27 |
+
used by both public and confidential clients.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'
|
| 31 |
+
|
| 32 |
+
def __init__(self, client_id, private_key=None, subject=None, issuer=None,
|
| 33 |
+
audience=None, **kwargs):
|
| 34 |
+
"""Initialize a JWT client with defaults for implicit use later.
|
| 35 |
+
|
| 36 |
+
:param client_id: Client identifier given by the OAuth provider upon
|
| 37 |
+
registration.
|
| 38 |
+
|
| 39 |
+
:param private_key: Private key used for signing and encrypting.
|
| 40 |
+
Must be given as a string.
|
| 41 |
+
|
| 42 |
+
:param subject: The principal that is the subject of the JWT, i.e.
|
| 43 |
+
which user is the token requested on behalf of.
|
| 44 |
+
For example, ``foo@example.com.
|
| 45 |
+
|
| 46 |
+
:param issuer: The JWT MUST contain an "iss" (issuer) claim that
|
| 47 |
+
contains a unique identifier for the entity that issued
|
| 48 |
+
the JWT. For example, ``your-client@provider.com``.
|
| 49 |
+
|
| 50 |
+
:param audience: A value identifying the authorization server as an
|
| 51 |
+
intended audience, e.g.
|
| 52 |
+
``https://provider.com/oauth2/token``.
|
| 53 |
+
|
| 54 |
+
:param kwargs: Additional arguments to pass to base client, such as
|
| 55 |
+
state and token. See ``Client.__init__.__doc__`` for
|
| 56 |
+
details.
|
| 57 |
+
"""
|
| 58 |
+
super().__init__(client_id, **kwargs)
|
| 59 |
+
self.private_key = private_key
|
| 60 |
+
self.subject = subject
|
| 61 |
+
self.issuer = issuer
|
| 62 |
+
self.audience = audience
|
| 63 |
+
|
| 64 |
+
def prepare_request_body(self,
|
| 65 |
+
private_key=None,
|
| 66 |
+
subject=None,
|
| 67 |
+
issuer=None,
|
| 68 |
+
audience=None,
|
| 69 |
+
expires_at=None,
|
| 70 |
+
issued_at=None,
|
| 71 |
+
extra_claims=None,
|
| 72 |
+
body='',
|
| 73 |
+
scope=None,
|
| 74 |
+
include_client_id=False,
|
| 75 |
+
**kwargs):
|
| 76 |
+
"""Create and add a JWT assertion to the request body.
|
| 77 |
+
|
| 78 |
+
:param private_key: Private key used for signing and encrypting.
|
| 79 |
+
Must be given as a string.
|
| 80 |
+
|
| 81 |
+
:param subject: (sub) The principal that is the subject of the JWT,
|
| 82 |
+
i.e. which user is the token requested on behalf of.
|
| 83 |
+
For example, ``foo@example.com.
|
| 84 |
+
|
| 85 |
+
:param issuer: (iss) The JWT MUST contain an "iss" (issuer) claim that
|
| 86 |
+
contains a unique identifier for the entity that issued
|
| 87 |
+
the JWT. For example, ``your-client@provider.com``.
|
| 88 |
+
|
| 89 |
+
:param audience: (aud) A value identifying the authorization server as an
|
| 90 |
+
intended audience, e.g.
|
| 91 |
+
``https://provider.com/oauth2/token``.
|
| 92 |
+
|
| 93 |
+
:param expires_at: A unix expiration timestamp for the JWT. Defaults
|
| 94 |
+
to an hour from now, i.e. ``time.time() + 3600``.
|
| 95 |
+
|
| 96 |
+
:param issued_at: A unix timestamp of when the JWT was created.
|
| 97 |
+
Defaults to now, i.e. ``time.time()``.
|
| 98 |
+
|
| 99 |
+
:param extra_claims: A dict of additional claims to include in the JWT.
|
| 100 |
+
|
| 101 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 102 |
+
into. This may contain extra parameters. Default ''.
|
| 103 |
+
|
| 104 |
+
:param scope: The scope of the access request.
|
| 105 |
+
|
| 106 |
+
:param include_client_id: `True` to send the `client_id` in the
|
| 107 |
+
body of the upstream request. This is required
|
| 108 |
+
if the client is not authenticating with the
|
| 109 |
+
authorization server as described in
|
| 110 |
+
`Section 3.2.1`_. False otherwise (default).
|
| 111 |
+
:type include_client_id: Boolean
|
| 112 |
+
|
| 113 |
+
:param not_before: A unix timestamp after which the JWT may be used.
|
| 114 |
+
Not included unless provided. *
|
| 115 |
+
|
| 116 |
+
:param jwt_id: A unique JWT token identifier. Not included unless
|
| 117 |
+
provided. *
|
| 118 |
+
|
| 119 |
+
:param kwargs: Extra credentials to include in the token request.
|
| 120 |
+
|
| 121 |
+
Parameters marked with a `*` above are not explicit arguments in the
|
| 122 |
+
function signature, but are specially documented arguments for items
|
| 123 |
+
appearing in the generic `**kwargs` keyworded input.
|
| 124 |
+
|
| 125 |
+
The "scope" parameter may be used, as defined in the Assertion
|
| 126 |
+
Framework for OAuth 2.0 Client Authentication and Authorization Grants
|
| 127 |
+
[I-D.ietf-oauth-assertions] specification, to indicate the requested
|
| 128 |
+
scope.
|
| 129 |
+
|
| 130 |
+
Authentication of the client is optional, as described in
|
| 131 |
+
`Section 3.2.1`_ of OAuth 2.0 [RFC6749] and consequently, the
|
| 132 |
+
"client_id" is only needed when a form of client authentication that
|
| 133 |
+
relies on the parameter is used.
|
| 134 |
+
|
| 135 |
+
The following non-normative example demonstrates an Access Token
|
| 136 |
+
Request with a JWT as an authorization grant (with extra line breaks
|
| 137 |
+
for display purposes only):
|
| 138 |
+
|
| 139 |
+
.. code-block: http
|
| 140 |
+
|
| 141 |
+
POST /token.oauth2 HTTP/1.1
|
| 142 |
+
Host: as.example.com
|
| 143 |
+
Content-Type: application/x-www-form-urlencoded
|
| 144 |
+
|
| 145 |
+
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer
|
| 146 |
+
&assertion=eyJhbGciOiJFUzI1NiJ9.
|
| 147 |
+
eyJpc3Mi[...omitted for brevity...].
|
| 148 |
+
J9l-ZhwP[...omitted for brevity...]
|
| 149 |
+
|
| 150 |
+
.. _`Section 3.2.1`: https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 151 |
+
"""
|
| 152 |
+
import jwt
|
| 153 |
+
|
| 154 |
+
key = private_key or self.private_key
|
| 155 |
+
if not key:
|
| 156 |
+
raise ValueError('An encryption key must be supplied to make JWT'
|
| 157 |
+
' token requests.')
|
| 158 |
+
claim = {
|
| 159 |
+
'iss': issuer or self.issuer,
|
| 160 |
+
'aud': audience or self.audience,
|
| 161 |
+
'sub': subject or self.subject,
|
| 162 |
+
'exp': int(expires_at or time.time() + 3600),
|
| 163 |
+
'iat': int(issued_at or time.time()),
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
for attr in ('iss', 'aud', 'sub'):
|
| 167 |
+
if claim[attr] is None:
|
| 168 |
+
raise ValueError(
|
| 169 |
+
'Claim must include %s but none was given.' % attr)
|
| 170 |
+
|
| 171 |
+
if 'not_before' in kwargs:
|
| 172 |
+
claim['nbf'] = kwargs.pop('not_before')
|
| 173 |
+
|
| 174 |
+
if 'jwt_id' in kwargs:
|
| 175 |
+
claim['jti'] = kwargs.pop('jwt_id')
|
| 176 |
+
|
| 177 |
+
claim.update(extra_claims or {})
|
| 178 |
+
|
| 179 |
+
assertion = jwt.encode(claim, key, 'RS256')
|
| 180 |
+
assertion = to_unicode(assertion)
|
| 181 |
+
|
| 182 |
+
kwargs['client_id'] = self.client_id
|
| 183 |
+
kwargs['include_client_id'] = include_client_id
|
| 184 |
+
scope = self.scope if scope is None else scope
|
| 185 |
+
return prepare_token_request(self.grant_type,
|
| 186 |
+
body=body,
|
| 187 |
+
assertion=assertion,
|
| 188 |
+
scope=scope,
|
| 189 |
+
**kwargs)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
oauthlib.oauth2.rfc6749
|
| 4 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 5 |
+
|
| 6 |
+
This module is an implementation of various logic needed
|
| 7 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 8 |
+
"""
|
| 9 |
+
import warnings
|
| 10 |
+
|
| 11 |
+
from ..parameters import (
|
| 12 |
+
parse_authorization_code_response, prepare_grant_uri,
|
| 13 |
+
prepare_token_request,
|
| 14 |
+
)
|
| 15 |
+
from .base import Client
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class WebApplicationClient(Client):
|
| 19 |
+
|
| 20 |
+
"""A client utilizing the authorization code grant workflow.
|
| 21 |
+
|
| 22 |
+
A web application is a confidential client running on a web
|
| 23 |
+
server. Resource owners access the client via an HTML user
|
| 24 |
+
interface rendered in a user-agent on the device used by the
|
| 25 |
+
resource owner. The client credentials as well as any access
|
| 26 |
+
token issued to the client are stored on the web server and are
|
| 27 |
+
not exposed to or accessible by the resource owner.
|
| 28 |
+
|
| 29 |
+
The authorization code grant type is used to obtain both access
|
| 30 |
+
tokens and refresh tokens and is optimized for confidential clients.
|
| 31 |
+
As a redirection-based flow, the client must be capable of
|
| 32 |
+
interacting with the resource owner's user-agent (typically a web
|
| 33 |
+
browser) and capable of receiving incoming requests (via redirection)
|
| 34 |
+
from the authorization server.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
grant_type = 'authorization_code'
|
| 38 |
+
|
| 39 |
+
def __init__(self, client_id, code=None, **kwargs):
|
| 40 |
+
super().__init__(client_id, **kwargs)
|
| 41 |
+
self.code = code
|
| 42 |
+
|
| 43 |
+
def prepare_request_uri(self, uri, redirect_uri=None, scope=None,
|
| 44 |
+
state=None, code_challenge=None, code_challenge_method='plain', **kwargs):
|
| 45 |
+
"""Prepare the authorization code request URI
|
| 46 |
+
|
| 47 |
+
The client constructs the request URI by adding the following
|
| 48 |
+
parameters to the query component of the authorization endpoint URI
|
| 49 |
+
using the "application/x-www-form-urlencoded" format, per `Appendix B`_:
|
| 50 |
+
|
| 51 |
+
:param redirect_uri: OPTIONAL. The redirect URI must be an absolute URI
|
| 52 |
+
and it should have been registered with the OAuth
|
| 53 |
+
provider prior to use. As described in `Section 3.1.2`_.
|
| 54 |
+
|
| 55 |
+
:param scope: OPTIONAL. The scope of the access request as described by
|
| 56 |
+
Section 3.3`_. These may be any string but are commonly
|
| 57 |
+
URIs or various categories such as ``videos`` or ``documents``.
|
| 58 |
+
|
| 59 |
+
:param state: RECOMMENDED. An opaque value used by the client to maintain
|
| 60 |
+
state between the request and callback. The authorization
|
| 61 |
+
server includes this value when redirecting the user-agent back
|
| 62 |
+
to the client. The parameter SHOULD be used for preventing
|
| 63 |
+
cross-site request forgery as described in `Section 10.12`_.
|
| 64 |
+
|
| 65 |
+
:param code_challenge: OPTIONAL. PKCE parameter. REQUIRED if PKCE is enforced.
|
| 66 |
+
A challenge derived from the code_verifier that is sent in the
|
| 67 |
+
authorization request, to be verified against later.
|
| 68 |
+
|
| 69 |
+
:param code_challenge_method: OPTIONAL. PKCE parameter. A method that was used to derive code challenge.
|
| 70 |
+
Defaults to "plain" if not present in the request.
|
| 71 |
+
|
| 72 |
+
:param kwargs: Extra arguments to include in the request URI.
|
| 73 |
+
|
| 74 |
+
In addition to supplied parameters, OAuthLib will append the ``client_id``
|
| 75 |
+
that was provided in the constructor as well as the mandatory ``response_type``
|
| 76 |
+
argument, set to ``code``::
|
| 77 |
+
|
| 78 |
+
>>> from oauthlib.oauth2 import WebApplicationClient
|
| 79 |
+
>>> client = WebApplicationClient('your_id')
|
| 80 |
+
>>> client.prepare_request_uri('https://example.com')
|
| 81 |
+
'https://example.com?client_id=your_id&response_type=code'
|
| 82 |
+
>>> client.prepare_request_uri('https://example.com', redirect_uri='https://a.b/callback')
|
| 83 |
+
'https://example.com?client_id=your_id&response_type=code&redirect_uri=https%3A%2F%2Fa.b%2Fcallback'
|
| 84 |
+
>>> client.prepare_request_uri('https://example.com', scope=['profile', 'pictures'])
|
| 85 |
+
'https://example.com?client_id=your_id&response_type=code&scope=profile+pictures'
|
| 86 |
+
>>> client.prepare_request_uri('https://example.com', code_challenge='kjasBS523KdkAILD2k78NdcJSk2k3KHG6')
|
| 87 |
+
'https://example.com?client_id=your_id&response_type=code&code_challenge=kjasBS523KdkAILD2k78NdcJSk2k3KHG6'
|
| 88 |
+
>>> client.prepare_request_uri('https://example.com', code_challenge_method='S256')
|
| 89 |
+
'https://example.com?client_id=your_id&response_type=code&code_challenge_method=S256'
|
| 90 |
+
>>> client.prepare_request_uri('https://example.com', foo='bar')
|
| 91 |
+
'https://example.com?client_id=your_id&response_type=code&foo=bar'
|
| 92 |
+
|
| 93 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 94 |
+
.. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2
|
| 95 |
+
.. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 96 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 97 |
+
.. _`Section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12
|
| 98 |
+
"""
|
| 99 |
+
scope = self.scope if scope is None else scope
|
| 100 |
+
return prepare_grant_uri(uri, self.client_id, 'code',
|
| 101 |
+
redirect_uri=redirect_uri, scope=scope, state=state, code_challenge=code_challenge,
|
| 102 |
+
code_challenge_method=code_challenge_method, **kwargs)
|
| 103 |
+
|
| 104 |
+
def prepare_request_body(self, code=None, redirect_uri=None, body='',
|
| 105 |
+
include_client_id=True, code_verifier=None, **kwargs):
|
| 106 |
+
"""Prepare the access token request body.
|
| 107 |
+
|
| 108 |
+
The client makes a request to the token endpoint by adding the
|
| 109 |
+
following parameters using the "application/x-www-form-urlencoded"
|
| 110 |
+
format in the HTTP request entity-body:
|
| 111 |
+
|
| 112 |
+
:param code: REQUIRED. The authorization code received from the
|
| 113 |
+
authorization server.
|
| 114 |
+
|
| 115 |
+
:param redirect_uri: REQUIRED, if the "redirect_uri" parameter was included in the
|
| 116 |
+
authorization request as described in `Section 4.1.1`_, and their
|
| 117 |
+
values MUST be identical.
|
| 118 |
+
|
| 119 |
+
:param body: Existing request body (URL encoded string) to embed parameters
|
| 120 |
+
into. This may contain extra parameters. Default ''.
|
| 121 |
+
|
| 122 |
+
:param include_client_id: `True` (default) to send the `client_id` in the
|
| 123 |
+
body of the upstream request. This is required
|
| 124 |
+
if the client is not authenticating with the
|
| 125 |
+
authorization server as described in `Section 3.2.1`_.
|
| 126 |
+
:type include_client_id: Boolean
|
| 127 |
+
|
| 128 |
+
:param code_verifier: OPTIONAL. A cryptographically random string that is used to correlate the
|
| 129 |
+
authorization request to the token request.
|
| 130 |
+
|
| 131 |
+
:param kwargs: Extra parameters to include in the token request.
|
| 132 |
+
|
| 133 |
+
In addition OAuthLib will add the ``grant_type`` parameter set to
|
| 134 |
+
``authorization_code``.
|
| 135 |
+
|
| 136 |
+
If the client type is confidential or the client was issued client
|
| 137 |
+
credentials (or assigned other authentication requirements), the
|
| 138 |
+
client MUST authenticate with the authorization server as described
|
| 139 |
+
in `Section 3.2.1`_::
|
| 140 |
+
|
| 141 |
+
>>> from oauthlib.oauth2 import WebApplicationClient
|
| 142 |
+
>>> client = WebApplicationClient('your_id')
|
| 143 |
+
>>> client.prepare_request_body(code='sh35ksdf09sf')
|
| 144 |
+
'grant_type=authorization_code&code=sh35ksdf09sf'
|
| 145 |
+
>>> client.prepare_request_body(code_verifier='KB46DCKJ873NCGXK5GD682NHDKK34GR')
|
| 146 |
+
'grant_type=authorization_code&code_verifier=KB46DCKJ873NCGXK5GD682NHDKK34GR'
|
| 147 |
+
>>> client.prepare_request_body(code='sh35ksdf09sf', foo='bar')
|
| 148 |
+
'grant_type=authorization_code&code=sh35ksdf09sf&foo=bar'
|
| 149 |
+
|
| 150 |
+
`Section 3.2.1` also states:
|
| 151 |
+
In the "authorization_code" "grant_type" request to the token
|
| 152 |
+
endpoint, an unauthenticated client MUST send its "client_id" to
|
| 153 |
+
prevent itself from inadvertently accepting a code intended for a
|
| 154 |
+
client with a different "client_id". This protects the client from
|
| 155 |
+
substitution of the authentication code. (It provides no additional
|
| 156 |
+
security for the protected resource.)
|
| 157 |
+
|
| 158 |
+
.. _`Section 4.1.1`: https://tools.ietf.org/html/rfc6749#section-4.1.1
|
| 159 |
+
.. _`Section 3.2.1`: https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 160 |
+
"""
|
| 161 |
+
code = code or self.code
|
| 162 |
+
if 'client_id' in kwargs:
|
| 163 |
+
warnings.warn("`client_id` has been deprecated in favor of "
|
| 164 |
+
"`include_client_id`, a boolean value which will "
|
| 165 |
+
"include the already configured `self.client_id`.",
|
| 166 |
+
DeprecationWarning)
|
| 167 |
+
if kwargs['client_id'] != self.client_id:
|
| 168 |
+
raise ValueError("`client_id` was supplied as an argument, but "
|
| 169 |
+
"it does not match `self.client_id`")
|
| 170 |
+
|
| 171 |
+
kwargs['client_id'] = self.client_id
|
| 172 |
+
kwargs['include_client_id'] = include_client_id
|
| 173 |
+
return prepare_token_request(self.grant_type, code=code, body=body,
|
| 174 |
+
redirect_uri=redirect_uri, code_verifier=code_verifier, **kwargs)
|
| 175 |
+
|
| 176 |
+
def parse_request_uri_response(self, uri, state=None):
|
| 177 |
+
"""Parse the URI query for code and state.
|
| 178 |
+
|
| 179 |
+
If the resource owner grants the access request, the authorization
|
| 180 |
+
server issues an authorization code and delivers it to the client by
|
| 181 |
+
adding the following parameters to the query component of the
|
| 182 |
+
redirection URI using the "application/x-www-form-urlencoded" format:
|
| 183 |
+
|
| 184 |
+
:param uri: The callback URI that resulted from the user being redirected
|
| 185 |
+
back from the provider to you, the client.
|
| 186 |
+
:param state: The state provided in the authorization request.
|
| 187 |
+
|
| 188 |
+
**code**
|
| 189 |
+
The authorization code generated by the authorization server.
|
| 190 |
+
The authorization code MUST expire shortly after it is issued
|
| 191 |
+
to mitigate the risk of leaks. A maximum authorization code
|
| 192 |
+
lifetime of 10 minutes is RECOMMENDED. The client MUST NOT
|
| 193 |
+
use the authorization code more than once. If an authorization
|
| 194 |
+
code is used more than once, the authorization server MUST deny
|
| 195 |
+
the request and SHOULD revoke (when possible) all tokens
|
| 196 |
+
previously issued based on that authorization code.
|
| 197 |
+
The authorization code is bound to the client identifier and
|
| 198 |
+
redirection URI.
|
| 199 |
+
|
| 200 |
+
**state**
|
| 201 |
+
If the "state" parameter was present in the authorization request.
|
| 202 |
+
|
| 203 |
+
This method is mainly intended to enforce strict state checking with
|
| 204 |
+
the added benefit of easily extracting parameters from the URI::
|
| 205 |
+
|
| 206 |
+
>>> from oauthlib.oauth2 import WebApplicationClient
|
| 207 |
+
>>> client = WebApplicationClient('your_id')
|
| 208 |
+
>>> uri = 'https://example.com/callback?code=sdfkjh345&state=sfetw45'
|
| 209 |
+
>>> client.parse_request_uri_response(uri, state='sfetw45')
|
| 210 |
+
{'state': 'sfetw45', 'code': 'sdfkjh345'}
|
| 211 |
+
>>> client.parse_request_uri_response(uri, state='other')
|
| 212 |
+
Traceback (most recent call last):
|
| 213 |
+
File "<stdin>", line 1, in <module>
|
| 214 |
+
File "oauthlib/oauth2/rfc6749/__init__.py", line 357, in parse_request_uri_response
|
| 215 |
+
back from the provider to you, the client.
|
| 216 |
+
File "oauthlib/oauth2/rfc6749/parameters.py", line 153, in parse_authorization_code_response
|
| 217 |
+
raise MismatchingStateError()
|
| 218 |
+
oauthlib.oauth2.rfc6749.errors.MismatchingStateError
|
| 219 |
+
"""
|
| 220 |
+
response = parse_authorization_code_response(uri, state=state)
|
| 221 |
+
self.populate_code_attributes(response)
|
| 222 |
+
return response
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (848 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/authorization.cpython-310.pyc
ADDED
|
Binary file (4.63 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (4.44 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/introspect.cpython-310.pyc
ADDED
|
Binary file (5.08 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/metadata.cpython-310.pyc
ADDED
|
Binary file (8.83 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/pre_configured.cpython-310.pyc
ADDED
|
Binary file (8.01 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/resource.cpython-310.pyc
ADDED
|
Binary file (3.89 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/revocation.cpython-310.pyc
ADDED
|
Binary file (5.18 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/__pycache__/token.cpython-310.pyc
ADDED
|
Binary file (4.32 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/authorization.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
This module is an implementation of various logic needed
|
| 6 |
+
for consuming and providing OAuth 2.0 RFC6749.
|
| 7 |
+
"""
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
from oauthlib.common import Request
|
| 11 |
+
from oauthlib.oauth2.rfc6749 import utils
|
| 12 |
+
|
| 13 |
+
from .base import BaseEndpoint, catch_errors_and_unavailability
|
| 14 |
+
|
| 15 |
+
log = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class AuthorizationEndpoint(BaseEndpoint):
|
| 19 |
+
|
| 20 |
+
"""Authorization endpoint - used by the client to obtain authorization
|
| 21 |
+
from the resource owner via user-agent redirection.
|
| 22 |
+
|
| 23 |
+
The authorization endpoint is used to interact with the resource
|
| 24 |
+
owner and obtain an authorization grant. The authorization server
|
| 25 |
+
MUST first verify the identity of the resource owner. The way in
|
| 26 |
+
which the authorization server authenticates the resource owner (e.g.
|
| 27 |
+
username and password login, session cookies) is beyond the scope of
|
| 28 |
+
this specification.
|
| 29 |
+
|
| 30 |
+
The endpoint URI MAY include an "application/x-www-form-urlencoded"
|
| 31 |
+
formatted (per `Appendix B`_) query component,
|
| 32 |
+
which MUST be retained when adding additional query parameters. The
|
| 33 |
+
endpoint URI MUST NOT include a fragment component::
|
| 34 |
+
|
| 35 |
+
https://example.com/path?query=component # OK
|
| 36 |
+
https://example.com/path?query=component#fragment # Not OK
|
| 37 |
+
|
| 38 |
+
Since requests to the authorization endpoint result in user
|
| 39 |
+
authentication and the transmission of clear-text credentials (in the
|
| 40 |
+
HTTP response), the authorization server MUST require the use of TLS
|
| 41 |
+
as described in Section 1.6 when sending requests to the
|
| 42 |
+
authorization endpoint::
|
| 43 |
+
|
| 44 |
+
# We will deny any request which URI schema is not with https
|
| 45 |
+
|
| 46 |
+
The authorization server MUST support the use of the HTTP "GET"
|
| 47 |
+
method [RFC2616] for the authorization endpoint, and MAY support the
|
| 48 |
+
use of the "POST" method as well::
|
| 49 |
+
|
| 50 |
+
# HTTP method is currently not enforced
|
| 51 |
+
|
| 52 |
+
Parameters sent without a value MUST be treated as if they were
|
| 53 |
+
omitted from the request. The authorization server MUST ignore
|
| 54 |
+
unrecognized request parameters. Request and response parameters
|
| 55 |
+
MUST NOT be included more than once::
|
| 56 |
+
|
| 57 |
+
# Enforced through the design of oauthlib.common.Request
|
| 58 |
+
|
| 59 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
def __init__(self, default_response_type, default_token_type,
|
| 63 |
+
response_types):
|
| 64 |
+
BaseEndpoint.__init__(self)
|
| 65 |
+
self._response_types = response_types
|
| 66 |
+
self._default_response_type = default_response_type
|
| 67 |
+
self._default_token_type = default_token_type
|
| 68 |
+
|
| 69 |
+
@property
|
| 70 |
+
def response_types(self):
|
| 71 |
+
return self._response_types
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
def default_response_type(self):
|
| 75 |
+
return self._default_response_type
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def default_response_type_handler(self):
|
| 79 |
+
return self.response_types.get(self.default_response_type)
|
| 80 |
+
|
| 81 |
+
@property
|
| 82 |
+
def default_token_type(self):
|
| 83 |
+
return self._default_token_type
|
| 84 |
+
|
| 85 |
+
@catch_errors_and_unavailability
|
| 86 |
+
def create_authorization_response(self, uri, http_method='GET', body=None,
|
| 87 |
+
headers=None, scopes=None, credentials=None):
|
| 88 |
+
"""Extract response_type and route to the designated handler."""
|
| 89 |
+
request = Request(
|
| 90 |
+
uri, http_method=http_method, body=body, headers=headers)
|
| 91 |
+
request.scopes = scopes
|
| 92 |
+
# TODO: decide whether this should be a required argument
|
| 93 |
+
request.user = None # TODO: explain this in docs
|
| 94 |
+
for k, v in (credentials or {}).items():
|
| 95 |
+
setattr(request, k, v)
|
| 96 |
+
response_type_handler = self.response_types.get(
|
| 97 |
+
request.response_type, self.default_response_type_handler)
|
| 98 |
+
log.debug('Dispatching response_type %s request to %r.',
|
| 99 |
+
request.response_type, response_type_handler)
|
| 100 |
+
return response_type_handler.create_authorization_response(
|
| 101 |
+
request, self.default_token_type)
|
| 102 |
+
|
| 103 |
+
@catch_errors_and_unavailability
|
| 104 |
+
def validate_authorization_request(self, uri, http_method='GET', body=None,
|
| 105 |
+
headers=None):
|
| 106 |
+
"""Extract response_type and route to the designated handler."""
|
| 107 |
+
request = Request(
|
| 108 |
+
uri, http_method=http_method, body=body, headers=headers)
|
| 109 |
+
|
| 110 |
+
request.scopes = utils.scope_to_list(request.scope)
|
| 111 |
+
|
| 112 |
+
response_type_handler = self.response_types.get(
|
| 113 |
+
request.response_type, self.default_response_type_handler)
|
| 114 |
+
return response_type_handler.validate_authorization_request(request)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/introspect.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749.endpoint.introspect
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
An implementation of the OAuth 2.0 `Token Introspection`.
|
| 6 |
+
|
| 7 |
+
.. _`Token Introspection`: https://tools.ietf.org/html/rfc7662
|
| 8 |
+
"""
|
| 9 |
+
import json
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
from oauthlib.common import Request
|
| 13 |
+
|
| 14 |
+
from ..errors import OAuth2Error
|
| 15 |
+
from .base import BaseEndpoint, catch_errors_and_unavailability
|
| 16 |
+
|
| 17 |
+
log = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class IntrospectEndpoint(BaseEndpoint):
|
| 21 |
+
|
| 22 |
+
"""Introspect token endpoint.
|
| 23 |
+
|
| 24 |
+
This endpoint defines a method to query an OAuth 2.0 authorization
|
| 25 |
+
server to determine the active state of an OAuth 2.0 token and to
|
| 26 |
+
determine meta-information about this token. OAuth 2.0 deployments
|
| 27 |
+
can use this method to convey information about the authorization
|
| 28 |
+
context of the token from the authorization server to the protected
|
| 29 |
+
resource.
|
| 30 |
+
|
| 31 |
+
To prevent the values of access tokens from leaking into
|
| 32 |
+
server-side logs via query parameters, an authorization server
|
| 33 |
+
offering token introspection MAY disallow the use of HTTP GET on
|
| 34 |
+
the introspection endpoint and instead require the HTTP POST method
|
| 35 |
+
to be used at the introspection endpoint.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
valid_token_types = ('access_token', 'refresh_token')
|
| 39 |
+
valid_request_methods = ('POST',)
|
| 40 |
+
|
| 41 |
+
def __init__(self, request_validator, supported_token_types=None):
|
| 42 |
+
BaseEndpoint.__init__(self)
|
| 43 |
+
self.request_validator = request_validator
|
| 44 |
+
self.supported_token_types = (
|
| 45 |
+
supported_token_types or self.valid_token_types)
|
| 46 |
+
|
| 47 |
+
@catch_errors_and_unavailability
|
| 48 |
+
def create_introspect_response(self, uri, http_method='POST', body=None,
|
| 49 |
+
headers=None):
|
| 50 |
+
"""Create introspect valid or invalid response
|
| 51 |
+
|
| 52 |
+
If the authorization server is unable to determine the state
|
| 53 |
+
of the token without additional information, it SHOULD return
|
| 54 |
+
an introspection response indicating the token is not active
|
| 55 |
+
as described in Section 2.2.
|
| 56 |
+
"""
|
| 57 |
+
resp_headers = {
|
| 58 |
+
'Content-Type': 'application/json',
|
| 59 |
+
'Cache-Control': 'no-store',
|
| 60 |
+
'Pragma': 'no-cache',
|
| 61 |
+
}
|
| 62 |
+
request = Request(uri, http_method, body, headers)
|
| 63 |
+
try:
|
| 64 |
+
self.validate_introspect_request(request)
|
| 65 |
+
log.debug('Token introspect valid for %r.', request)
|
| 66 |
+
except OAuth2Error as e:
|
| 67 |
+
log.debug('Client error during validation of %r. %r.', request, e)
|
| 68 |
+
resp_headers.update(e.headers)
|
| 69 |
+
return resp_headers, e.json, e.status_code
|
| 70 |
+
|
| 71 |
+
claims = self.request_validator.introspect_token(
|
| 72 |
+
request.token,
|
| 73 |
+
request.token_type_hint,
|
| 74 |
+
request
|
| 75 |
+
)
|
| 76 |
+
if claims is None:
|
| 77 |
+
return resp_headers, json.dumps(dict(active=False)), 200
|
| 78 |
+
if "active" in claims:
|
| 79 |
+
claims.pop("active")
|
| 80 |
+
return resp_headers, json.dumps(dict(active=True, **claims)), 200
|
| 81 |
+
|
| 82 |
+
def validate_introspect_request(self, request):
|
| 83 |
+
"""Ensure the request is valid.
|
| 84 |
+
|
| 85 |
+
The protected resource calls the introspection endpoint using
|
| 86 |
+
an HTTP POST request with parameters sent as
|
| 87 |
+
"application/x-www-form-urlencoded".
|
| 88 |
+
|
| 89 |
+
* token REQUIRED. The string value of the token.
|
| 90 |
+
* token_type_hint OPTIONAL.
|
| 91 |
+
|
| 92 |
+
A hint about the type of the token submitted for
|
| 93 |
+
introspection. The protected resource MAY pass this parameter to
|
| 94 |
+
help the authorization server optimize the token lookup. If the
|
| 95 |
+
server is unable to locate the token using the given hint, it MUST
|
| 96 |
+
extend its search across all of its supported token types. An
|
| 97 |
+
authorization server MAY ignore this parameter, particularly if it
|
| 98 |
+
is able to detect the token type automatically.
|
| 99 |
+
|
| 100 |
+
* access_token: An Access Token as defined in [`RFC6749`], `section 1.4`_
|
| 101 |
+
* refresh_token: A Refresh Token as defined in [`RFC6749`], `section 1.5`_
|
| 102 |
+
|
| 103 |
+
The introspection endpoint MAY accept other OPTIONAL
|
| 104 |
+
parameters to provide further context to the query. For
|
| 105 |
+
instance, an authorization server may desire to know the IP
|
| 106 |
+
address of the client accessing the protected resource to
|
| 107 |
+
determine if the correct client is likely to be presenting the
|
| 108 |
+
token. The definition of this or any other parameters are
|
| 109 |
+
outside the scope of this specification, to be defined by
|
| 110 |
+
service documentation or extensions to this specification.
|
| 111 |
+
|
| 112 |
+
.. _`section 1.4`: http://tools.ietf.org/html/rfc6749#section-1.4
|
| 113 |
+
.. _`section 1.5`: http://tools.ietf.org/html/rfc6749#section-1.5
|
| 114 |
+
.. _`RFC6749`: http://tools.ietf.org/html/rfc6749
|
| 115 |
+
"""
|
| 116 |
+
self._raise_on_bad_method(request)
|
| 117 |
+
self._raise_on_bad_post_request(request)
|
| 118 |
+
self._raise_on_missing_token(request)
|
| 119 |
+
self._raise_on_invalid_client(request)
|
| 120 |
+
self._raise_on_unsupported_token(request)
|
evalkit_tf446/lib/python3.10/site-packages/oauth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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749.endpoints.pre_configured
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
This module is an implementation of various endpoints needed
|
| 6 |
+
for providing OAuth 2.0 RFC6749 servers.
|
| 7 |
+
"""
|
| 8 |
+
from ..grant_types import (
|
| 9 |
+
AuthorizationCodeGrant, ClientCredentialsGrant, ImplicitGrant,
|
| 10 |
+
RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant,
|
| 11 |
+
)
|
| 12 |
+
from ..tokens import BearerToken
|
| 13 |
+
from .authorization import AuthorizationEndpoint
|
| 14 |
+
from .introspect import IntrospectEndpoint
|
| 15 |
+
from .resource import ResourceEndpoint
|
| 16 |
+
from .revocation import RevocationEndpoint
|
| 17 |
+
from .token import TokenEndpoint
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class Server(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint,
|
| 21 |
+
ResourceEndpoint, RevocationEndpoint):
|
| 22 |
+
|
| 23 |
+
"""An all-in-one endpoint featuring all four major grant types."""
|
| 24 |
+
|
| 25 |
+
def __init__(self, request_validator, token_expires_in=None,
|
| 26 |
+
token_generator=None, refresh_token_generator=None,
|
| 27 |
+
*args, **kwargs):
|
| 28 |
+
"""Construct a new all-grants-in-one server.
|
| 29 |
+
|
| 30 |
+
:param request_validator: An implementation of
|
| 31 |
+
oauthlib.oauth2.RequestValidator.
|
| 32 |
+
:param token_expires_in: An int or a function to generate a token
|
| 33 |
+
expiration offset (in seconds) given a
|
| 34 |
+
oauthlib.common.Request object.
|
| 35 |
+
:param token_generator: A function to generate a token from a request.
|
| 36 |
+
:param refresh_token_generator: A function to generate a token from a
|
| 37 |
+
request for the refresh token.
|
| 38 |
+
:param kwargs: Extra parameters to pass to authorization-,
|
| 39 |
+
token-, resource-, and revocation-endpoint constructors.
|
| 40 |
+
"""
|
| 41 |
+
self.auth_grant = AuthorizationCodeGrant(request_validator)
|
| 42 |
+
self.implicit_grant = ImplicitGrant(request_validator)
|
| 43 |
+
self.password_grant = ResourceOwnerPasswordCredentialsGrant(
|
| 44 |
+
request_validator)
|
| 45 |
+
self.credentials_grant = ClientCredentialsGrant(request_validator)
|
| 46 |
+
self.refresh_grant = RefreshTokenGrant(request_validator)
|
| 47 |
+
|
| 48 |
+
self.bearer = BearerToken(request_validator, token_generator,
|
| 49 |
+
token_expires_in, refresh_token_generator)
|
| 50 |
+
|
| 51 |
+
AuthorizationEndpoint.__init__(self, default_response_type='code',
|
| 52 |
+
response_types={
|
| 53 |
+
'code': self.auth_grant,
|
| 54 |
+
'token': self.implicit_grant,
|
| 55 |
+
'none': self.auth_grant
|
| 56 |
+
},
|
| 57 |
+
default_token_type=self.bearer)
|
| 58 |
+
|
| 59 |
+
TokenEndpoint.__init__(self, default_grant_type='authorization_code',
|
| 60 |
+
grant_types={
|
| 61 |
+
'authorization_code': self.auth_grant,
|
| 62 |
+
'password': self.password_grant,
|
| 63 |
+
'client_credentials': self.credentials_grant,
|
| 64 |
+
'refresh_token': self.refresh_grant,
|
| 65 |
+
},
|
| 66 |
+
default_token_type=self.bearer)
|
| 67 |
+
ResourceEndpoint.__init__(self, default_token='Bearer',
|
| 68 |
+
token_types={'Bearer': self.bearer})
|
| 69 |
+
RevocationEndpoint.__init__(self, request_validator)
|
| 70 |
+
IntrospectEndpoint.__init__(self, request_validator)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class WebApplicationServer(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint,
|
| 74 |
+
ResourceEndpoint, RevocationEndpoint):
|
| 75 |
+
|
| 76 |
+
"""An all-in-one endpoint featuring Authorization code grant and Bearer tokens."""
|
| 77 |
+
|
| 78 |
+
def __init__(self, request_validator, token_generator=None,
|
| 79 |
+
token_expires_in=None, refresh_token_generator=None, **kwargs):
|
| 80 |
+
"""Construct a new web application server.
|
| 81 |
+
|
| 82 |
+
:param request_validator: An implementation of
|
| 83 |
+
oauthlib.oauth2.RequestValidator.
|
| 84 |
+
:param token_expires_in: An int or a function to generate a token
|
| 85 |
+
expiration offset (in seconds) given a
|
| 86 |
+
oauthlib.common.Request object.
|
| 87 |
+
:param token_generator: A function to generate a token from a request.
|
| 88 |
+
:param refresh_token_generator: A function to generate a token from a
|
| 89 |
+
request for the refresh token.
|
| 90 |
+
:param kwargs: Extra parameters to pass to authorization-,
|
| 91 |
+
token-, resource-, and revocation-endpoint constructors.
|
| 92 |
+
"""
|
| 93 |
+
self.auth_grant = AuthorizationCodeGrant(request_validator)
|
| 94 |
+
self.refresh_grant = RefreshTokenGrant(request_validator)
|
| 95 |
+
self.bearer = BearerToken(request_validator, token_generator,
|
| 96 |
+
token_expires_in, refresh_token_generator)
|
| 97 |
+
AuthorizationEndpoint.__init__(self, default_response_type='code',
|
| 98 |
+
response_types={'code': self.auth_grant},
|
| 99 |
+
default_token_type=self.bearer)
|
| 100 |
+
TokenEndpoint.__init__(self, default_grant_type='authorization_code',
|
| 101 |
+
grant_types={
|
| 102 |
+
'authorization_code': self.auth_grant,
|
| 103 |
+
'refresh_token': self.refresh_grant,
|
| 104 |
+
},
|
| 105 |
+
default_token_type=self.bearer)
|
| 106 |
+
ResourceEndpoint.__init__(self, default_token='Bearer',
|
| 107 |
+
token_types={'Bearer': self.bearer})
|
| 108 |
+
RevocationEndpoint.__init__(self, request_validator)
|
| 109 |
+
IntrospectEndpoint.__init__(self, request_validator)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class MobileApplicationServer(AuthorizationEndpoint, IntrospectEndpoint,
|
| 113 |
+
ResourceEndpoint, RevocationEndpoint):
|
| 114 |
+
|
| 115 |
+
"""An all-in-one endpoint featuring Implicit code grant and Bearer tokens."""
|
| 116 |
+
|
| 117 |
+
def __init__(self, request_validator, token_generator=None,
|
| 118 |
+
token_expires_in=None, refresh_token_generator=None, **kwargs):
|
| 119 |
+
"""Construct a new implicit grant server.
|
| 120 |
+
|
| 121 |
+
:param request_validator: An implementation of
|
| 122 |
+
oauthlib.oauth2.RequestValidator.
|
| 123 |
+
:param token_expires_in: An int or a function to generate a token
|
| 124 |
+
expiration offset (in seconds) given a
|
| 125 |
+
oauthlib.common.Request object.
|
| 126 |
+
:param token_generator: A function to generate a token from a request.
|
| 127 |
+
:param refresh_token_generator: A function to generate a token from a
|
| 128 |
+
request for the refresh token.
|
| 129 |
+
:param kwargs: Extra parameters to pass to authorization-,
|
| 130 |
+
token-, resource-, and revocation-endpoint constructors.
|
| 131 |
+
"""
|
| 132 |
+
self.implicit_grant = ImplicitGrant(request_validator)
|
| 133 |
+
self.bearer = BearerToken(request_validator, token_generator,
|
| 134 |
+
token_expires_in, refresh_token_generator)
|
| 135 |
+
AuthorizationEndpoint.__init__(self, default_response_type='token',
|
| 136 |
+
response_types={
|
| 137 |
+
'token': self.implicit_grant},
|
| 138 |
+
default_token_type=self.bearer)
|
| 139 |
+
ResourceEndpoint.__init__(self, default_token='Bearer',
|
| 140 |
+
token_types={'Bearer': self.bearer})
|
| 141 |
+
RevocationEndpoint.__init__(self, request_validator,
|
| 142 |
+
supported_token_types=['access_token'])
|
| 143 |
+
IntrospectEndpoint.__init__(self, request_validator,
|
| 144 |
+
supported_token_types=['access_token'])
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
class LegacyApplicationServer(TokenEndpoint, IntrospectEndpoint,
|
| 148 |
+
ResourceEndpoint, RevocationEndpoint):
|
| 149 |
+
|
| 150 |
+
"""An all-in-one endpoint featuring Resource Owner Password Credentials grant and Bearer tokens."""
|
| 151 |
+
|
| 152 |
+
def __init__(self, request_validator, token_generator=None,
|
| 153 |
+
token_expires_in=None, refresh_token_generator=None, **kwargs):
|
| 154 |
+
"""Construct a resource owner password credentials grant server.
|
| 155 |
+
|
| 156 |
+
:param request_validator: An implementation of
|
| 157 |
+
oauthlib.oauth2.RequestValidator.
|
| 158 |
+
:param token_expires_in: An int or a function to generate a token
|
| 159 |
+
expiration offset (in seconds) given a
|
| 160 |
+
oauthlib.common.Request object.
|
| 161 |
+
:param token_generator: A function to generate a token from a request.
|
| 162 |
+
:param refresh_token_generator: A function to generate a token from a
|
| 163 |
+
request for the refresh token.
|
| 164 |
+
:param kwargs: Extra parameters to pass to authorization-,
|
| 165 |
+
token-, resource-, and revocation-endpoint constructors.
|
| 166 |
+
"""
|
| 167 |
+
self.password_grant = ResourceOwnerPasswordCredentialsGrant(
|
| 168 |
+
request_validator)
|
| 169 |
+
self.refresh_grant = RefreshTokenGrant(request_validator)
|
| 170 |
+
self.bearer = BearerToken(request_validator, token_generator,
|
| 171 |
+
token_expires_in, refresh_token_generator)
|
| 172 |
+
TokenEndpoint.__init__(self, default_grant_type='password',
|
| 173 |
+
grant_types={
|
| 174 |
+
'password': self.password_grant,
|
| 175 |
+
'refresh_token': self.refresh_grant,
|
| 176 |
+
},
|
| 177 |
+
default_token_type=self.bearer)
|
| 178 |
+
ResourceEndpoint.__init__(self, default_token='Bearer',
|
| 179 |
+
token_types={'Bearer': self.bearer})
|
| 180 |
+
RevocationEndpoint.__init__(self, request_validator)
|
| 181 |
+
IntrospectEndpoint.__init__(self, request_validator)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
class BackendApplicationServer(TokenEndpoint, IntrospectEndpoint,
|
| 185 |
+
ResourceEndpoint, RevocationEndpoint):
|
| 186 |
+
|
| 187 |
+
"""An all-in-one endpoint featuring Client Credentials grant and Bearer tokens."""
|
| 188 |
+
|
| 189 |
+
def __init__(self, request_validator, token_generator=None,
|
| 190 |
+
token_expires_in=None, refresh_token_generator=None, **kwargs):
|
| 191 |
+
"""Construct a client credentials grant server.
|
| 192 |
+
|
| 193 |
+
:param request_validator: An implementation of
|
| 194 |
+
oauthlib.oauth2.RequestValidator.
|
| 195 |
+
:param token_expires_in: An int or a function to generate a token
|
| 196 |
+
expiration offset (in seconds) given a
|
| 197 |
+
oauthlib.common.Request object.
|
| 198 |
+
:param token_generator: A function to generate a token from a request.
|
| 199 |
+
:param refresh_token_generator: A function to generate a token from a
|
| 200 |
+
request for the refresh token.
|
| 201 |
+
:param kwargs: Extra parameters to pass to authorization-,
|
| 202 |
+
token-, resource-, and revocation-endpoint constructors.
|
| 203 |
+
"""
|
| 204 |
+
self.credentials_grant = ClientCredentialsGrant(request_validator)
|
| 205 |
+
self.bearer = BearerToken(request_validator, token_generator,
|
| 206 |
+
token_expires_in, refresh_token_generator)
|
| 207 |
+
TokenEndpoint.__init__(self, default_grant_type='client_credentials',
|
| 208 |
+
grant_types={
|
| 209 |
+
'client_credentials': self.credentials_grant},
|
| 210 |
+
default_token_type=self.bearer)
|
| 211 |
+
ResourceEndpoint.__init__(self, default_token='Bearer',
|
| 212 |
+
token_types={'Bearer': self.bearer})
|
| 213 |
+
RevocationEndpoint.__init__(self, request_validator,
|
| 214 |
+
supported_token_types=['access_token'])
|
| 215 |
+
IntrospectEndpoint.__init__(self, request_validator,
|
| 216 |
+
supported_token_types=['access_token'])
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/endpoints/revocation.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749.endpoint.revocation
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
|
| 5 |
+
An implementation of the OAuth 2 `Token Revocation`_ spec (draft 11).
|
| 6 |
+
|
| 7 |
+
.. _`Token Revocation`: https://tools.ietf.org/html/draft-ietf-oauth-revocation-11
|
| 8 |
+
"""
|
| 9 |
+
import logging
|
| 10 |
+
|
| 11 |
+
from oauthlib.common import Request
|
| 12 |
+
|
| 13 |
+
from ..errors import OAuth2Error
|
| 14 |
+
from .base import BaseEndpoint, catch_errors_and_unavailability
|
| 15 |
+
|
| 16 |
+
log = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class RevocationEndpoint(BaseEndpoint):
|
| 20 |
+
|
| 21 |
+
"""Token revocation endpoint.
|
| 22 |
+
|
| 23 |
+
Endpoint used by authenticated clients to revoke access and refresh tokens.
|
| 24 |
+
Commonly this will be part of the Authorization Endpoint.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
valid_token_types = ('access_token', 'refresh_token')
|
| 28 |
+
valid_request_methods = ('POST',)
|
| 29 |
+
|
| 30 |
+
def __init__(self, request_validator, supported_token_types=None,
|
| 31 |
+
enable_jsonp=False):
|
| 32 |
+
BaseEndpoint.__init__(self)
|
| 33 |
+
self.request_validator = request_validator
|
| 34 |
+
self.supported_token_types = (
|
| 35 |
+
supported_token_types or self.valid_token_types)
|
| 36 |
+
self.enable_jsonp = enable_jsonp
|
| 37 |
+
|
| 38 |
+
@catch_errors_and_unavailability
|
| 39 |
+
def create_revocation_response(self, uri, http_method='POST', body=None,
|
| 40 |
+
headers=None):
|
| 41 |
+
"""Revoke supplied access or refresh token.
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
The authorization server responds with HTTP status code 200 if the
|
| 45 |
+
token has been revoked successfully or if the client submitted an
|
| 46 |
+
invalid token.
|
| 47 |
+
|
| 48 |
+
Note: invalid tokens do not cause an error response since the client
|
| 49 |
+
cannot handle such an error in a reasonable way. Moreover, the purpose
|
| 50 |
+
of the revocation request, invalidating the particular token, is
|
| 51 |
+
already achieved.
|
| 52 |
+
|
| 53 |
+
The content of the response body is ignored by the client as all
|
| 54 |
+
necessary information is conveyed in the response code.
|
| 55 |
+
|
| 56 |
+
An invalid token type hint value is ignored by the authorization server
|
| 57 |
+
and does not influence the revocation response.
|
| 58 |
+
"""
|
| 59 |
+
resp_headers = {
|
| 60 |
+
'Content-Type': 'application/json',
|
| 61 |
+
'Cache-Control': 'no-store',
|
| 62 |
+
'Pragma': 'no-cache',
|
| 63 |
+
}
|
| 64 |
+
request = Request(
|
| 65 |
+
uri, http_method=http_method, body=body, headers=headers)
|
| 66 |
+
try:
|
| 67 |
+
self.validate_revocation_request(request)
|
| 68 |
+
log.debug('Token revocation valid for %r.', request)
|
| 69 |
+
except OAuth2Error as e:
|
| 70 |
+
log.debug('Client error during validation of %r. %r.', request, e)
|
| 71 |
+
response_body = e.json
|
| 72 |
+
if self.enable_jsonp and request.callback:
|
| 73 |
+
response_body = '{}({});'.format(request.callback, response_body)
|
| 74 |
+
resp_headers.update(e.headers)
|
| 75 |
+
return resp_headers, response_body, e.status_code
|
| 76 |
+
|
| 77 |
+
self.request_validator.revoke_token(request.token,
|
| 78 |
+
request.token_type_hint, request)
|
| 79 |
+
|
| 80 |
+
response_body = ''
|
| 81 |
+
if self.enable_jsonp and request.callback:
|
| 82 |
+
response_body = request.callback + '();'
|
| 83 |
+
return {}, response_body, 200
|
| 84 |
+
|
| 85 |
+
def validate_revocation_request(self, request):
|
| 86 |
+
"""Ensure the request is valid.
|
| 87 |
+
|
| 88 |
+
The client constructs the request by including the following parameters
|
| 89 |
+
using the "application/x-www-form-urlencoded" format in the HTTP
|
| 90 |
+
request entity-body:
|
| 91 |
+
|
| 92 |
+
token (REQUIRED). The token that the client wants to get revoked.
|
| 93 |
+
|
| 94 |
+
token_type_hint (OPTIONAL). A hint about the type of the token
|
| 95 |
+
submitted for revocation. Clients MAY pass this parameter in order to
|
| 96 |
+
help the authorization server to optimize the token lookup. If the
|
| 97 |
+
server is unable to locate the token using the given hint, it MUST
|
| 98 |
+
extend its search across all of its supported token types. An
|
| 99 |
+
authorization server MAY ignore this parameter, particularly if it is
|
| 100 |
+
able to detect the token type automatically. This specification
|
| 101 |
+
defines two such values:
|
| 102 |
+
|
| 103 |
+
* access_token: An Access Token as defined in [RFC6749],
|
| 104 |
+
`section 1.4`_
|
| 105 |
+
|
| 106 |
+
* refresh_token: A Refresh Token as defined in [RFC6749],
|
| 107 |
+
`section 1.5`_
|
| 108 |
+
|
| 109 |
+
Specific implementations, profiles, and extensions of this
|
| 110 |
+
specification MAY define other values for this parameter using
|
| 111 |
+
the registry defined in `Section 4.1.2`_.
|
| 112 |
+
|
| 113 |
+
The client also includes its authentication credentials as described in
|
| 114 |
+
`Section 2.3`_. of [`RFC6749`_].
|
| 115 |
+
|
| 116 |
+
.. _`section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4
|
| 117 |
+
.. _`section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5
|
| 118 |
+
.. _`section 2.3`: https://tools.ietf.org/html/rfc6749#section-2.3
|
| 119 |
+
.. _`Section 4.1.2`: https://tools.ietf.org/html/draft-ietf-oauth-revocation-11#section-4.1.2
|
| 120 |
+
.. _`RFC6749`: https://tools.ietf.org/html/rfc6749
|
| 121 |
+
"""
|
| 122 |
+
self._raise_on_bad_method(request)
|
| 123 |
+
self._raise_on_bad_post_request(request)
|
| 124 |
+
self._raise_on_missing_token(request)
|
| 125 |
+
self._raise_on_invalid_client(request)
|
| 126 |
+
self._raise_on_unsupported_token(request)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749.grant_types
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
"""
|
| 5 |
+
from .authorization_code import AuthorizationCodeGrant
|
| 6 |
+
from .client_credentials import ClientCredentialsGrant
|
| 7 |
+
from .implicit import ImplicitGrant
|
| 8 |
+
from .refresh_token import RefreshTokenGrant
|
| 9 |
+
from .resource_owner_password_credentials import (
|
| 10 |
+
ResourceOwnerPasswordCredentialsGrant,
|
| 11 |
+
)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (613 Bytes). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/authorization_code.cpython-310.pyc
ADDED
|
Binary file (18.3 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (9.26 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/client_credentials.cpython-310.pyc
ADDED
|
Binary file (4.78 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/implicit.cpython-310.pyc
ADDED
|
Binary file (12.9 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/refresh_token.cpython-310.pyc
ADDED
|
Binary file (4.63 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/__pycache__/resource_owner_password_credentials.cpython-310.pyc
ADDED
|
Binary file (7.75 kB). View file
|
|
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
ADDED
|
@@ -0,0 +1,548 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
import json
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
from oauthlib import common
|
| 11 |
+
|
| 12 |
+
from .. import errors
|
| 13 |
+
from .base import GrantTypeBase
|
| 14 |
+
|
| 15 |
+
log = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def code_challenge_method_s256(verifier, challenge):
|
| 19 |
+
"""
|
| 20 |
+
If the "code_challenge_method" from `Section 4.3`_ was "S256", the
|
| 21 |
+
received "code_verifier" is hashed by SHA-256, base64url-encoded, and
|
| 22 |
+
then compared to the "code_challenge", i.e.:
|
| 23 |
+
|
| 24 |
+
BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge
|
| 25 |
+
|
| 26 |
+
How to implement a base64url-encoding
|
| 27 |
+
function without padding, based upon the standard base64-encoding
|
| 28 |
+
function that uses padding.
|
| 29 |
+
|
| 30 |
+
To be concrete, example C# code implementing these functions is shown
|
| 31 |
+
below. Similar code could be used in other languages.
|
| 32 |
+
|
| 33 |
+
static string base64urlencode(byte [] arg)
|
| 34 |
+
{
|
| 35 |
+
string s = Convert.ToBase64String(arg); // Regular base64 encoder
|
| 36 |
+
s = s.Split('=')[0]; // Remove any trailing '='s
|
| 37 |
+
s = s.Replace('+', '-'); // 62nd char of encoding
|
| 38 |
+
s = s.Replace('/', '_'); // 63rd char of encoding
|
| 39 |
+
return s;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
In python urlsafe_b64encode is already replacing '+' and '/', but preserve
|
| 43 |
+
the trailing '='. So we have to remove it.
|
| 44 |
+
|
| 45 |
+
.. _`Section 4.3`: https://tools.ietf.org/html/rfc7636#section-4.3
|
| 46 |
+
"""
|
| 47 |
+
return base64.urlsafe_b64encode(
|
| 48 |
+
hashlib.sha256(verifier.encode()).digest()
|
| 49 |
+
).decode().rstrip('=') == challenge
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def code_challenge_method_plain(verifier, challenge):
|
| 53 |
+
"""
|
| 54 |
+
If the "code_challenge_method" from `Section 4.3`_ was "plain", they are
|
| 55 |
+
compared directly, i.e.:
|
| 56 |
+
|
| 57 |
+
code_verifier == code_challenge.
|
| 58 |
+
|
| 59 |
+
.. _`Section 4.3`: https://tools.ietf.org/html/rfc7636#section-4.3
|
| 60 |
+
"""
|
| 61 |
+
return verifier == challenge
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class AuthorizationCodeGrant(GrantTypeBase):
|
| 65 |
+
|
| 66 |
+
"""`Authorization Code Grant`_
|
| 67 |
+
|
| 68 |
+
The authorization code grant type is used to obtain both access
|
| 69 |
+
tokens and refresh tokens and is optimized for confidential clients.
|
| 70 |
+
Since this is a redirection-based flow, the client must be capable of
|
| 71 |
+
interacting with the resource owner's user-agent (typically a web
|
| 72 |
+
browser) and capable of receiving incoming requests (via redirection)
|
| 73 |
+
from the authorization server::
|
| 74 |
+
|
| 75 |
+
+----------+
|
| 76 |
+
| Resource |
|
| 77 |
+
| Owner |
|
| 78 |
+
| |
|
| 79 |
+
+----------+
|
| 80 |
+
^
|
| 81 |
+
|
|
| 82 |
+
(B)
|
| 83 |
+
+----|-----+ Client Identifier +---------------+
|
| 84 |
+
| -+----(A)-- & Redirection URI ---->| |
|
| 85 |
+
| User- | | Authorization |
|
| 86 |
+
| Agent -+----(B)-- User authenticates --->| Server |
|
| 87 |
+
| | | |
|
| 88 |
+
| -+----(C)-- Authorization Code ---<| |
|
| 89 |
+
+-|----|---+ +---------------+
|
| 90 |
+
| | ^ v
|
| 91 |
+
(A) (C) | |
|
| 92 |
+
| | | |
|
| 93 |
+
^ v | |
|
| 94 |
+
+---------+ | |
|
| 95 |
+
| |>---(D)-- Authorization Code ---------' |
|
| 96 |
+
| Client | & Redirection URI |
|
| 97 |
+
| | |
|
| 98 |
+
| |<---(E)----- Access Token -------------------'
|
| 99 |
+
+---------+ (w/ Optional Refresh Token)
|
| 100 |
+
|
| 101 |
+
Note: The lines illustrating steps (A), (B), and (C) are broken into
|
| 102 |
+
two parts as they pass through the user-agent.
|
| 103 |
+
|
| 104 |
+
Figure 3: Authorization Code Flow
|
| 105 |
+
|
| 106 |
+
The flow illustrated in Figure 3 includes the following steps:
|
| 107 |
+
|
| 108 |
+
(A) The client initiates the flow by directing the resource owner's
|
| 109 |
+
user-agent to the authorization endpoint. The client includes
|
| 110 |
+
its client identifier, requested scope, local state, and a
|
| 111 |
+
redirection URI to which the authorization server will send the
|
| 112 |
+
user-agent back once access is granted (or denied).
|
| 113 |
+
|
| 114 |
+
(B) The authorization server authenticates the resource owner (via
|
| 115 |
+
the user-agent) and establishes whether the resource owner
|
| 116 |
+
grants or denies the client's access request.
|
| 117 |
+
|
| 118 |
+
(C) Assuming the resource owner grants access, the authorization
|
| 119 |
+
server redirects the user-agent back to the client using the
|
| 120 |
+
redirection URI provided earlier (in the request or during
|
| 121 |
+
client registration). The redirection URI includes an
|
| 122 |
+
authorization code and any local state provided by the client
|
| 123 |
+
earlier.
|
| 124 |
+
|
| 125 |
+
(D) The client requests an access token from the authorization
|
| 126 |
+
server's token endpoint by including the authorization code
|
| 127 |
+
received in the previous step. When making the request, the
|
| 128 |
+
client authenticates with the authorization server. The client
|
| 129 |
+
includes the redirection URI used to obtain the authorization
|
| 130 |
+
code for verification.
|
| 131 |
+
|
| 132 |
+
(E) The authorization server authenticates the client, validates the
|
| 133 |
+
authorization code, and ensures that the redirection URI
|
| 134 |
+
received matches the URI used to redirect the client in
|
| 135 |
+
step (C). If valid, the authorization server responds back with
|
| 136 |
+
an access token and, optionally, a refresh token.
|
| 137 |
+
|
| 138 |
+
OAuth 2.0 public clients utilizing the Authorization Code Grant are
|
| 139 |
+
susceptible to the authorization code interception attack.
|
| 140 |
+
|
| 141 |
+
A technique to mitigate against the threat through the use of Proof Key for Code
|
| 142 |
+
Exchange (PKCE, pronounced "pixy") is implemented in the current oauthlib
|
| 143 |
+
implementation.
|
| 144 |
+
|
| 145 |
+
.. _`Authorization Code Grant`: https://tools.ietf.org/html/rfc6749#section-4.1
|
| 146 |
+
.. _`PKCE`: https://tools.ietf.org/html/rfc7636
|
| 147 |
+
"""
|
| 148 |
+
|
| 149 |
+
default_response_mode = 'query'
|
| 150 |
+
response_types = ['code']
|
| 151 |
+
|
| 152 |
+
# This dict below is private because as RFC mention it:
|
| 153 |
+
# "S256" is Mandatory To Implement (MTI) on the server.
|
| 154 |
+
#
|
| 155 |
+
_code_challenge_methods = {
|
| 156 |
+
'plain': code_challenge_method_plain,
|
| 157 |
+
'S256': code_challenge_method_s256
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
def create_authorization_code(self, request):
|
| 161 |
+
"""
|
| 162 |
+
Generates an authorization grant represented as a dictionary.
|
| 163 |
+
|
| 164 |
+
:param request: OAuthlib request.
|
| 165 |
+
:type request: oauthlib.common.Request
|
| 166 |
+
"""
|
| 167 |
+
grant = {'code': common.generate_token()}
|
| 168 |
+
if hasattr(request, 'state') and request.state:
|
| 169 |
+
grant['state'] = request.state
|
| 170 |
+
log.debug('Created authorization code grant %r for request %r.',
|
| 171 |
+
grant, request)
|
| 172 |
+
return grant
|
| 173 |
+
|
| 174 |
+
def create_authorization_response(self, request, token_handler):
|
| 175 |
+
"""
|
| 176 |
+
The client constructs the request URI by adding the following
|
| 177 |
+
parameters to the query component of the authorization endpoint URI
|
| 178 |
+
using the "application/x-www-form-urlencoded" format, per `Appendix B`_:
|
| 179 |
+
|
| 180 |
+
response_type
|
| 181 |
+
REQUIRED. Value MUST be set to "code" for standard OAuth2
|
| 182 |
+
authorization flow. For OpenID Connect it must be one of
|
| 183 |
+
"code token", "code id_token", or "code token id_token" - we
|
| 184 |
+
essentially test that "code" appears in the response_type.
|
| 185 |
+
client_id
|
| 186 |
+
REQUIRED. The client identifier as described in `Section 2.2`_.
|
| 187 |
+
redirect_uri
|
| 188 |
+
OPTIONAL. As described in `Section 3.1.2`_.
|
| 189 |
+
scope
|
| 190 |
+
OPTIONAL. The scope of the access request as described by
|
| 191 |
+
`Section 3.3`_.
|
| 192 |
+
state
|
| 193 |
+
RECOMMENDED. An opaque value used by the client to maintain
|
| 194 |
+
state between the request and callback. The authorization
|
| 195 |
+
server includes this value when redirecting the user-agent back
|
| 196 |
+
to the client. The parameter SHOULD be used for preventing
|
| 197 |
+
cross-site request forgery as described in `Section 10.12`_.
|
| 198 |
+
|
| 199 |
+
The client directs the resource owner to the constructed URI using an
|
| 200 |
+
HTTP redirection response, or by other means available to it via the
|
| 201 |
+
user-agent.
|
| 202 |
+
|
| 203 |
+
:param request: OAuthlib request.
|
| 204 |
+
:type request: oauthlib.common.Request
|
| 205 |
+
:param token_handler: A token handler instance, for example of type
|
| 206 |
+
oauthlib.oauth2.BearerToken.
|
| 207 |
+
:returns: headers, body, status
|
| 208 |
+
:raises: FatalClientError on invalid redirect URI or client id.
|
| 209 |
+
|
| 210 |
+
A few examples::
|
| 211 |
+
|
| 212 |
+
>>> from your_validator import your_validator
|
| 213 |
+
>>> request = Request('https://example.com/authorize?client_id=valid'
|
| 214 |
+
... '&redirect_uri=http%3A%2F%2Fclient.com%2F')
|
| 215 |
+
>>> from oauthlib.common import Request
|
| 216 |
+
>>> from oauthlib.oauth2 import AuthorizationCodeGrant, BearerToken
|
| 217 |
+
>>> token = BearerToken(your_validator)
|
| 218 |
+
>>> grant = AuthorizationCodeGrant(your_validator)
|
| 219 |
+
>>> request.scopes = ['authorized', 'in', 'some', 'form']
|
| 220 |
+
>>> grant.create_authorization_response(request, token)
|
| 221 |
+
(u'http://client.com/?error=invalid_request&error_description=Missing+response_type+parameter.', None, None, 400)
|
| 222 |
+
>>> request = Request('https://example.com/authorize?client_id=valid'
|
| 223 |
+
... '&redirect_uri=http%3A%2F%2Fclient.com%2F'
|
| 224 |
+
... '&response_type=code')
|
| 225 |
+
>>> request.scopes = ['authorized', 'in', 'some', 'form']
|
| 226 |
+
>>> grant.create_authorization_response(request, token)
|
| 227 |
+
(u'http://client.com/?code=u3F05aEObJuP2k7DordviIgW5wl52N', None, None, 200)
|
| 228 |
+
>>> # If the client id or redirect uri fails validation
|
| 229 |
+
>>> grant.create_authorization_response(request, token)
|
| 230 |
+
Traceback (most recent call last):
|
| 231 |
+
File "<stdin>", line 1, in <module>
|
| 232 |
+
File "oauthlib/oauth2/rfc6749/grant_types.py", line 515, in create_authorization_response
|
| 233 |
+
>>> grant.create_authorization_response(request, token)
|
| 234 |
+
File "oauthlib/oauth2/rfc6749/grant_types.py", line 591, in validate_authorization_request
|
| 235 |
+
oauthlib.oauth2.rfc6749.errors.InvalidClientIdError
|
| 236 |
+
|
| 237 |
+
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
|
| 238 |
+
.. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2
|
| 239 |
+
.. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 240 |
+
.. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
|
| 241 |
+
.. _`Section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12
|
| 242 |
+
"""
|
| 243 |
+
try:
|
| 244 |
+
self.validate_authorization_request(request)
|
| 245 |
+
log.debug('Pre resource owner authorization validation ok for %r.',
|
| 246 |
+
request)
|
| 247 |
+
|
| 248 |
+
# If the request fails due to a missing, invalid, or mismatching
|
| 249 |
+
# redirection URI, or if the client identifier is missing or invalid,
|
| 250 |
+
# the authorization server SHOULD inform the resource owner of the
|
| 251 |
+
# error and MUST NOT automatically redirect the user-agent to the
|
| 252 |
+
# invalid redirection URI.
|
| 253 |
+
except errors.FatalClientError as e:
|
| 254 |
+
log.debug('Fatal client error during validation of %r. %r.',
|
| 255 |
+
request, e)
|
| 256 |
+
raise
|
| 257 |
+
|
| 258 |
+
# If the resource owner denies the access request or if the request
|
| 259 |
+
# fails for reasons other than a missing or invalid redirection URI,
|
| 260 |
+
# the authorization server informs the client by adding the following
|
| 261 |
+
# parameters to the query component of the redirection URI using the
|
| 262 |
+
# "application/x-www-form-urlencoded" format, per Appendix B:
|
| 263 |
+
# https://tools.ietf.org/html/rfc6749#appendix-B
|
| 264 |
+
except errors.OAuth2Error as e:
|
| 265 |
+
log.debug('Client error during validation of %r. %r.', request, e)
|
| 266 |
+
request.redirect_uri = request.redirect_uri or self.error_uri
|
| 267 |
+
redirect_uri = common.add_params_to_uri(
|
| 268 |
+
request.redirect_uri, e.twotuples,
|
| 269 |
+
fragment=request.response_mode == "fragment")
|
| 270 |
+
return {'Location': redirect_uri}, None, 302
|
| 271 |
+
|
| 272 |
+
grant = self.create_authorization_code(request)
|
| 273 |
+
for modifier in self._code_modifiers:
|
| 274 |
+
grant = modifier(grant, token_handler, request)
|
| 275 |
+
if 'access_token' in grant:
|
| 276 |
+
self.request_validator.save_token(grant, request)
|
| 277 |
+
log.debug('Saving grant %r for %r.', grant, request)
|
| 278 |
+
self.request_validator.save_authorization_code(
|
| 279 |
+
request.client_id, grant, request)
|
| 280 |
+
return self.prepare_authorization_response(
|
| 281 |
+
request, grant, {}, None, 302)
|
| 282 |
+
|
| 283 |
+
def create_token_response(self, request, token_handler):
|
| 284 |
+
"""Validate the authorization code.
|
| 285 |
+
|
| 286 |
+
The client MUST NOT use the authorization code more than once. If an
|
| 287 |
+
authorization code is used more than once, the authorization server
|
| 288 |
+
MUST deny the request and SHOULD revoke (when possible) all tokens
|
| 289 |
+
previously issued based on that authorization code. The authorization
|
| 290 |
+
code is bound to the client identifier and redirection URI.
|
| 291 |
+
|
| 292 |
+
:param request: OAuthlib request.
|
| 293 |
+
:type request: oauthlib.common.Request
|
| 294 |
+
:param token_handler: A token handler instance, for example of type
|
| 295 |
+
oauthlib.oauth2.BearerToken.
|
| 296 |
+
|
| 297 |
+
"""
|
| 298 |
+
headers = self._get_default_headers()
|
| 299 |
+
try:
|
| 300 |
+
self.validate_token_request(request)
|
| 301 |
+
log.debug('Token request validation ok for %r.', request)
|
| 302 |
+
except errors.OAuth2Error as e:
|
| 303 |
+
log.debug('Client error during validation of %r. %r.', request, e)
|
| 304 |
+
headers.update(e.headers)
|
| 305 |
+
return headers, e.json, e.status_code
|
| 306 |
+
|
| 307 |
+
token = token_handler.create_token(request, refresh_token=self.refresh_token)
|
| 308 |
+
|
| 309 |
+
for modifier in self._token_modifiers:
|
| 310 |
+
token = modifier(token, token_handler, request)
|
| 311 |
+
|
| 312 |
+
self.request_validator.save_token(token, request)
|
| 313 |
+
self.request_validator.invalidate_authorization_code(
|
| 314 |
+
request.client_id, request.code, request)
|
| 315 |
+
headers.update(self._create_cors_headers(request))
|
| 316 |
+
return headers, json.dumps(token), 200
|
| 317 |
+
|
| 318 |
+
def validate_authorization_request(self, request):
|
| 319 |
+
"""Check the authorization request for normal and fatal errors.
|
| 320 |
+
|
| 321 |
+
A normal error could be a missing response_type parameter or the client
|
| 322 |
+
attempting to access scope it is not allowed to ask authorization for.
|
| 323 |
+
Normal errors can safely be included in the redirection URI and
|
| 324 |
+
sent back to the client.
|
| 325 |
+
|
| 326 |
+
Fatal errors occur when the client_id or redirect_uri is invalid or
|
| 327 |
+
missing. These must be caught by the provider and handled, how this
|
| 328 |
+
is done is outside of the scope of OAuthLib but showing an error
|
| 329 |
+
page describing the issue is a good idea.
|
| 330 |
+
|
| 331 |
+
:param request: OAuthlib request.
|
| 332 |
+
:type request: oauthlib.common.Request
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
# First check for fatal errors
|
| 336 |
+
|
| 337 |
+
# If the request fails due to a missing, invalid, or mismatching
|
| 338 |
+
# redirection URI, or if the client identifier is missing or invalid,
|
| 339 |
+
# the authorization server SHOULD inform the resource owner of the
|
| 340 |
+
# error and MUST NOT automatically redirect the user-agent to the
|
| 341 |
+
# invalid redirection URI.
|
| 342 |
+
|
| 343 |
+
# First check duplicate parameters
|
| 344 |
+
for param in ('client_id', 'response_type', 'redirect_uri', 'scope', 'state'):
|
| 345 |
+
try:
|
| 346 |
+
duplicate_params = request.duplicate_params
|
| 347 |
+
except ValueError:
|
| 348 |
+
raise errors.InvalidRequestFatalError(description='Unable to parse query string', request=request)
|
| 349 |
+
if param in duplicate_params:
|
| 350 |
+
raise errors.InvalidRequestFatalError(description='Duplicate %s parameter.' % param, request=request)
|
| 351 |
+
|
| 352 |
+
# REQUIRED. The client identifier as described in Section 2.2.
|
| 353 |
+
# https://tools.ietf.org/html/rfc6749#section-2.2
|
| 354 |
+
if not request.client_id:
|
| 355 |
+
raise errors.MissingClientIdError(request=request)
|
| 356 |
+
|
| 357 |
+
if not self.request_validator.validate_client_id(request.client_id, request):
|
| 358 |
+
raise errors.InvalidClientIdError(request=request)
|
| 359 |
+
|
| 360 |
+
# OPTIONAL. As described in Section 3.1.2.
|
| 361 |
+
# https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 362 |
+
log.debug('Validating redirection uri %s for client %s.',
|
| 363 |
+
request.redirect_uri, request.client_id)
|
| 364 |
+
|
| 365 |
+
# OPTIONAL. As described in Section 3.1.2.
|
| 366 |
+
# https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 367 |
+
self._handle_redirects(request)
|
| 368 |
+
|
| 369 |
+
# Then check for normal errors.
|
| 370 |
+
|
| 371 |
+
# If the resource owner denies the access request or if the request
|
| 372 |
+
# fails for reasons other than a missing or invalid redirection URI,
|
| 373 |
+
# the authorization server informs the client by adding the following
|
| 374 |
+
# parameters to the query component of the redirection URI using the
|
| 375 |
+
# "application/x-www-form-urlencoded" format, per Appendix B.
|
| 376 |
+
# https://tools.ietf.org/html/rfc6749#appendix-B
|
| 377 |
+
|
| 378 |
+
# Note that the correct parameters to be added are automatically
|
| 379 |
+
# populated through the use of specific exceptions.
|
| 380 |
+
|
| 381 |
+
request_info = {}
|
| 382 |
+
for validator in self.custom_validators.pre_auth:
|
| 383 |
+
request_info.update(validator(request))
|
| 384 |
+
|
| 385 |
+
# REQUIRED.
|
| 386 |
+
if request.response_type is None:
|
| 387 |
+
raise errors.MissingResponseTypeError(request=request)
|
| 388 |
+
# Value MUST be set to "code" or one of the OpenID authorization code including
|
| 389 |
+
# response_types "code token", "code id_token", "code token id_token"
|
| 390 |
+
elif not 'code' in request.response_type and request.response_type != 'none':
|
| 391 |
+
raise errors.UnsupportedResponseTypeError(request=request)
|
| 392 |
+
|
| 393 |
+
if not self.request_validator.validate_response_type(request.client_id,
|
| 394 |
+
request.response_type,
|
| 395 |
+
request.client, request):
|
| 396 |
+
|
| 397 |
+
log.debug('Client %s is not authorized to use response_type %s.',
|
| 398 |
+
request.client_id, request.response_type)
|
| 399 |
+
raise errors.UnauthorizedClientError(request=request)
|
| 400 |
+
|
| 401 |
+
# OPTIONAL. Validate PKCE request or reply with "error"/"invalid_request"
|
| 402 |
+
# https://tools.ietf.org/html/rfc6749#section-4.4.1
|
| 403 |
+
if self.request_validator.is_pkce_required(request.client_id, request) is True:
|
| 404 |
+
if request.code_challenge is None:
|
| 405 |
+
raise errors.MissingCodeChallengeError(request=request)
|
| 406 |
+
|
| 407 |
+
if request.code_challenge is not None:
|
| 408 |
+
request_info["code_challenge"] = request.code_challenge
|
| 409 |
+
|
| 410 |
+
# OPTIONAL, defaults to "plain" if not present in the request.
|
| 411 |
+
if request.code_challenge_method is None:
|
| 412 |
+
request.code_challenge_method = "plain"
|
| 413 |
+
|
| 414 |
+
if request.code_challenge_method not in self._code_challenge_methods:
|
| 415 |
+
raise errors.UnsupportedCodeChallengeMethodError(request=request)
|
| 416 |
+
request_info["code_challenge_method"] = request.code_challenge_method
|
| 417 |
+
|
| 418 |
+
# OPTIONAL. The scope of the access request as described by Section 3.3
|
| 419 |
+
# https://tools.ietf.org/html/rfc6749#section-3.3
|
| 420 |
+
self.validate_scopes(request)
|
| 421 |
+
|
| 422 |
+
request_info.update({
|
| 423 |
+
'client_id': request.client_id,
|
| 424 |
+
'redirect_uri': request.redirect_uri,
|
| 425 |
+
'response_type': request.response_type,
|
| 426 |
+
'state': request.state,
|
| 427 |
+
'request': request
|
| 428 |
+
})
|
| 429 |
+
|
| 430 |
+
for validator in self.custom_validators.post_auth:
|
| 431 |
+
request_info.update(validator(request))
|
| 432 |
+
|
| 433 |
+
return request.scopes, request_info
|
| 434 |
+
|
| 435 |
+
def validate_token_request(self, request):
|
| 436 |
+
"""
|
| 437 |
+
:param request: OAuthlib request.
|
| 438 |
+
:type request: oauthlib.common.Request
|
| 439 |
+
"""
|
| 440 |
+
# REQUIRED. Value MUST be set to "authorization_code".
|
| 441 |
+
if request.grant_type not in ('authorization_code', 'openid'):
|
| 442 |
+
raise errors.UnsupportedGrantTypeError(request=request)
|
| 443 |
+
|
| 444 |
+
for validator in self.custom_validators.pre_token:
|
| 445 |
+
validator(request)
|
| 446 |
+
|
| 447 |
+
if request.code is None:
|
| 448 |
+
raise errors.InvalidRequestError(
|
| 449 |
+
description='Missing code parameter.', request=request)
|
| 450 |
+
|
| 451 |
+
for param in ('client_id', 'grant_type', 'redirect_uri'):
|
| 452 |
+
if param in request.duplicate_params:
|
| 453 |
+
raise errors.InvalidRequestError(description='Duplicate %s parameter.' % param,
|
| 454 |
+
request=request)
|
| 455 |
+
|
| 456 |
+
if self.request_validator.client_authentication_required(request):
|
| 457 |
+
# If the client type is confidential or the client was issued client
|
| 458 |
+
# credentials (or assigned other authentication requirements), the
|
| 459 |
+
# client MUST authenticate with the authorization server as described
|
| 460 |
+
# in Section 3.2.1.
|
| 461 |
+
# https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 462 |
+
if not self.request_validator.authenticate_client(request):
|
| 463 |
+
log.debug('Client authentication failed, %r.', request)
|
| 464 |
+
raise errors.InvalidClientError(request=request)
|
| 465 |
+
elif not self.request_validator.authenticate_client_id(request.client_id, request):
|
| 466 |
+
# REQUIRED, if the client is not authenticating with the
|
| 467 |
+
# authorization server as described in Section 3.2.1.
|
| 468 |
+
# https://tools.ietf.org/html/rfc6749#section-3.2.1
|
| 469 |
+
log.debug('Client authentication failed, %r.', request)
|
| 470 |
+
raise errors.InvalidClientError(request=request)
|
| 471 |
+
|
| 472 |
+
if not hasattr(request.client, 'client_id'):
|
| 473 |
+
raise NotImplementedError('Authenticate client must set the '
|
| 474 |
+
'request.client.client_id attribute '
|
| 475 |
+
'in authenticate_client.')
|
| 476 |
+
|
| 477 |
+
request.client_id = request.client_id or request.client.client_id
|
| 478 |
+
|
| 479 |
+
# Ensure client is authorized use of this grant type
|
| 480 |
+
self.validate_grant_type(request)
|
| 481 |
+
|
| 482 |
+
# REQUIRED. The authorization code received from the
|
| 483 |
+
# authorization server.
|
| 484 |
+
if not self.request_validator.validate_code(request.client_id,
|
| 485 |
+
request.code, request.client, request):
|
| 486 |
+
log.debug('Client, %r (%r), is not allowed access to scopes %r.',
|
| 487 |
+
request.client_id, request.client, request.scopes)
|
| 488 |
+
raise errors.InvalidGrantError(request=request)
|
| 489 |
+
|
| 490 |
+
# OPTIONAL. Validate PKCE code_verifier
|
| 491 |
+
challenge = self.request_validator.get_code_challenge(request.code, request)
|
| 492 |
+
|
| 493 |
+
if challenge is not None:
|
| 494 |
+
if request.code_verifier is None:
|
| 495 |
+
raise errors.MissingCodeVerifierError(request=request)
|
| 496 |
+
|
| 497 |
+
challenge_method = self.request_validator.get_code_challenge_method(request.code, request)
|
| 498 |
+
if challenge_method is None:
|
| 499 |
+
raise errors.InvalidGrantError(request=request, description="Challenge method not found")
|
| 500 |
+
|
| 501 |
+
if challenge_method not in self._code_challenge_methods:
|
| 502 |
+
raise errors.ServerError(
|
| 503 |
+
description="code_challenge_method {} is not supported.".format(challenge_method),
|
| 504 |
+
request=request
|
| 505 |
+
)
|
| 506 |
+
|
| 507 |
+
if not self.validate_code_challenge(challenge,
|
| 508 |
+
challenge_method,
|
| 509 |
+
request.code_verifier):
|
| 510 |
+
log.debug('request provided a invalid code_verifier.')
|
| 511 |
+
raise errors.InvalidGrantError(request=request)
|
| 512 |
+
elif self.request_validator.is_pkce_required(request.client_id, request) is True:
|
| 513 |
+
if request.code_verifier is None:
|
| 514 |
+
raise errors.MissingCodeVerifierError(request=request)
|
| 515 |
+
raise errors.InvalidGrantError(request=request, description="Challenge not found")
|
| 516 |
+
|
| 517 |
+
for attr in ('user', 'scopes'):
|
| 518 |
+
if getattr(request, attr, None) is None:
|
| 519 |
+
log.debug('request.%s was not set on code validation.', attr)
|
| 520 |
+
|
| 521 |
+
# REQUIRED, if the "redirect_uri" parameter was included in the
|
| 522 |
+
# authorization request as described in Section 4.1.1, and their
|
| 523 |
+
# values MUST be identical.
|
| 524 |
+
if request.redirect_uri is None:
|
| 525 |
+
request.using_default_redirect_uri = True
|
| 526 |
+
request.redirect_uri = self.request_validator.get_default_redirect_uri(
|
| 527 |
+
request.client_id, request)
|
| 528 |
+
log.debug('Using default redirect_uri %s.', request.redirect_uri)
|
| 529 |
+
if not request.redirect_uri:
|
| 530 |
+
raise errors.MissingRedirectURIError(request=request)
|
| 531 |
+
else:
|
| 532 |
+
request.using_default_redirect_uri = False
|
| 533 |
+
log.debug('Using provided redirect_uri %s', request.redirect_uri)
|
| 534 |
+
|
| 535 |
+
if not self.request_validator.confirm_redirect_uri(request.client_id, request.code,
|
| 536 |
+
request.redirect_uri, request.client,
|
| 537 |
+
request):
|
| 538 |
+
log.debug('Redirect_uri (%r) invalid for client %r (%r).',
|
| 539 |
+
request.redirect_uri, request.client_id, request.client)
|
| 540 |
+
raise errors.MismatchingRedirectURIError(request=request)
|
| 541 |
+
|
| 542 |
+
for validator in self.custom_validators.post_token:
|
| 543 |
+
validator(request)
|
| 544 |
+
|
| 545 |
+
def validate_code_challenge(self, challenge, challenge_method, verifier):
|
| 546 |
+
if challenge_method in self._code_challenge_methods:
|
| 547 |
+
return self._code_challenge_methods[challenge_method](verifier, challenge)
|
| 548 |
+
raise NotImplementedError('Unknown challenge_method %s' % challenge_method)
|
evalkit_tf446/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/grant_types/base.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
oauthlib.oauth2.rfc6749.grant_types
|
| 3 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
+
"""
|
| 5 |
+
import logging
|
| 6 |
+
from itertools import chain
|
| 7 |
+
|
| 8 |
+
from oauthlib.common import add_params_to_uri
|
| 9 |
+
from oauthlib.oauth2.rfc6749 import errors, utils
|
| 10 |
+
from oauthlib.uri_validate import is_absolute_uri
|
| 11 |
+
|
| 12 |
+
from ..request_validator import RequestValidator
|
| 13 |
+
from ..utils import is_secure_transport
|
| 14 |
+
|
| 15 |
+
log = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ValidatorsContainer:
|
| 19 |
+
"""
|
| 20 |
+
Container object for holding custom validator callables to be invoked
|
| 21 |
+
as part of the grant type `validate_authorization_request()` or
|
| 22 |
+
`validate_authorization_request()` methods on the various grant types.
|
| 23 |
+
|
| 24 |
+
Authorization validators must be callables that take a request object and
|
| 25 |
+
return a dict, which may contain items to be added to the `request_info`
|
| 26 |
+
returned from the grant_type after validation.
|
| 27 |
+
|
| 28 |
+
Token validators must be callables that take a request object and
|
| 29 |
+
return None.
|
| 30 |
+
|
| 31 |
+
Both authorization validators and token validators may raise OAuth2
|
| 32 |
+
exceptions if validation conditions fail.
|
| 33 |
+
|
| 34 |
+
Authorization validators added to `pre_auth` will be run BEFORE
|
| 35 |
+
the standard validations (but after the critical ones that raise
|
| 36 |
+
fatal errors) as part of `validate_authorization_request()`
|
| 37 |
+
|
| 38 |
+
Authorization validators added to `post_auth` will be run AFTER
|
| 39 |
+
the standard validations as part of `validate_authorization_request()`
|
| 40 |
+
|
| 41 |
+
Token validators added to `pre_token` will be run BEFORE
|
| 42 |
+
the standard validations as part of `validate_token_request()`
|
| 43 |
+
|
| 44 |
+
Token validators added to `post_token` will be run AFTER
|
| 45 |
+
the standard validations as part of `validate_token_request()`
|
| 46 |
+
|
| 47 |
+
For example:
|
| 48 |
+
|
| 49 |
+
>>> def my_auth_validator(request):
|
| 50 |
+
... return {'myval': True}
|
| 51 |
+
>>> auth_code_grant = AuthorizationCodeGrant(request_validator)
|
| 52 |
+
>>> auth_code_grant.custom_validators.pre_auth.append(my_auth_validator)
|
| 53 |
+
>>> def my_token_validator(request):
|
| 54 |
+
... if not request.everything_okay:
|
| 55 |
+
... raise errors.OAuth2Error("uh-oh")
|
| 56 |
+
>>> auth_code_grant.custom_validators.post_token.append(my_token_validator)
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def __init__(self, post_auth, post_token,
|
| 60 |
+
pre_auth, pre_token):
|
| 61 |
+
self.pre_auth = pre_auth
|
| 62 |
+
self.post_auth = post_auth
|
| 63 |
+
self.pre_token = pre_token
|
| 64 |
+
self.post_token = post_token
|
| 65 |
+
|
| 66 |
+
@property
|
| 67 |
+
def all_pre(self):
|
| 68 |
+
return chain(self.pre_auth, self.pre_token)
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def all_post(self):
|
| 72 |
+
return chain(self.post_auth, self.post_token)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class GrantTypeBase:
|
| 76 |
+
error_uri = None
|
| 77 |
+
request_validator = None
|
| 78 |
+
default_response_mode = 'fragment'
|
| 79 |
+
refresh_token = True
|
| 80 |
+
response_types = ['code']
|
| 81 |
+
|
| 82 |
+
def __init__(self, request_validator=None, **kwargs):
|
| 83 |
+
self.request_validator = request_validator or RequestValidator()
|
| 84 |
+
|
| 85 |
+
# Transforms class variables into instance variables:
|
| 86 |
+
self.response_types = self.response_types
|
| 87 |
+
self.refresh_token = self.refresh_token
|
| 88 |
+
self._setup_custom_validators(kwargs)
|
| 89 |
+
self._code_modifiers = []
|
| 90 |
+
self._token_modifiers = []
|
| 91 |
+
|
| 92 |
+
for kw, val in kwargs.items():
|
| 93 |
+
setattr(self, kw, val)
|
| 94 |
+
|
| 95 |
+
def _setup_custom_validators(self, kwargs):
|
| 96 |
+
post_auth = kwargs.get('post_auth', [])
|
| 97 |
+
post_token = kwargs.get('post_token', [])
|
| 98 |
+
pre_auth = kwargs.get('pre_auth', [])
|
| 99 |
+
pre_token = kwargs.get('pre_token', [])
|
| 100 |
+
if not hasattr(self, 'validate_authorization_request'):
|
| 101 |
+
if post_auth or pre_auth:
|
| 102 |
+
msg = ("{} does not support authorization validators. Use "
|
| 103 |
+
"token validators instead.").format(self.__class__.__name__)
|
| 104 |
+
raise ValueError(msg)
|
| 105 |
+
# Using tuples here because they can't be appended to:
|
| 106 |
+
post_auth, pre_auth = (), ()
|
| 107 |
+
self.custom_validators = ValidatorsContainer(post_auth, post_token,
|
| 108 |
+
pre_auth, pre_token)
|
| 109 |
+
|
| 110 |
+
def register_response_type(self, response_type):
|
| 111 |
+
self.response_types.append(response_type)
|
| 112 |
+
|
| 113 |
+
def register_code_modifier(self, modifier):
|
| 114 |
+
self._code_modifiers.append(modifier)
|
| 115 |
+
|
| 116 |
+
def register_token_modifier(self, modifier):
|
| 117 |
+
self._token_modifiers.append(modifier)
|
| 118 |
+
|
| 119 |
+
def create_authorization_response(self, request, token_handler):
|
| 120 |
+
"""
|
| 121 |
+
:param request: OAuthlib request.
|
| 122 |
+
:type request: oauthlib.common.Request
|
| 123 |
+
:param token_handler: A token handler instance, for example of type
|
| 124 |
+
oauthlib.oauth2.BearerToken.
|
| 125 |
+
"""
|
| 126 |
+
raise NotImplementedError('Subclasses must implement this method.')
|
| 127 |
+
|
| 128 |
+
def create_token_response(self, request, token_handler):
|
| 129 |
+
"""
|
| 130 |
+
:param request: OAuthlib request.
|
| 131 |
+
:type request: oauthlib.common.Request
|
| 132 |
+
:param token_handler: A token handler instance, for example of type
|
| 133 |
+
oauthlib.oauth2.BearerToken.
|
| 134 |
+
"""
|
| 135 |
+
raise NotImplementedError('Subclasses must implement this method.')
|
| 136 |
+
|
| 137 |
+
def add_token(self, token, token_handler, request):
|
| 138 |
+
"""
|
| 139 |
+
:param token:
|
| 140 |
+
:param token_handler: A token handler instance, for example of type
|
| 141 |
+
oauthlib.oauth2.BearerToken.
|
| 142 |
+
:param request: OAuthlib request.
|
| 143 |
+
:type request: oauthlib.common.Request
|
| 144 |
+
"""
|
| 145 |
+
# Only add a hybrid access token on auth step if asked for
|
| 146 |
+
if not request.response_type in ["token", "code token", "id_token token", "code id_token token"]:
|
| 147 |
+
return token
|
| 148 |
+
|
| 149 |
+
token.update(token_handler.create_token(request, refresh_token=False))
|
| 150 |
+
return token
|
| 151 |
+
|
| 152 |
+
def validate_grant_type(self, request):
|
| 153 |
+
"""
|
| 154 |
+
:param request: OAuthlib request.
|
| 155 |
+
:type request: oauthlib.common.Request
|
| 156 |
+
"""
|
| 157 |
+
client_id = getattr(request, 'client_id', None)
|
| 158 |
+
if not self.request_validator.validate_grant_type(client_id,
|
| 159 |
+
request.grant_type, request.client, request):
|
| 160 |
+
log.debug('Unauthorized from %r (%r) access to grant type %s.',
|
| 161 |
+
request.client_id, request.client, request.grant_type)
|
| 162 |
+
raise errors.UnauthorizedClientError(request=request)
|
| 163 |
+
|
| 164 |
+
def validate_scopes(self, request):
|
| 165 |
+
"""
|
| 166 |
+
:param request: OAuthlib request.
|
| 167 |
+
:type request: oauthlib.common.Request
|
| 168 |
+
"""
|
| 169 |
+
if not request.scopes:
|
| 170 |
+
request.scopes = utils.scope_to_list(request.scope) or utils.scope_to_list(
|
| 171 |
+
self.request_validator.get_default_scopes(request.client_id, request))
|
| 172 |
+
log.debug('Validating access to scopes %r for client %r (%r).',
|
| 173 |
+
request.scopes, request.client_id, request.client)
|
| 174 |
+
if not self.request_validator.validate_scopes(request.client_id,
|
| 175 |
+
request.scopes, request.client, request):
|
| 176 |
+
raise errors.InvalidScopeError(request=request)
|
| 177 |
+
|
| 178 |
+
def prepare_authorization_response(self, request, token, headers, body, status):
|
| 179 |
+
"""Place token according to response mode.
|
| 180 |
+
|
| 181 |
+
Base classes can define a default response mode for their authorization
|
| 182 |
+
response by overriding the static `default_response_mode` member.
|
| 183 |
+
|
| 184 |
+
:param request: OAuthlib request.
|
| 185 |
+
:type request: oauthlib.common.Request
|
| 186 |
+
:param token:
|
| 187 |
+
:param headers:
|
| 188 |
+
:param body:
|
| 189 |
+
:param status:
|
| 190 |
+
"""
|
| 191 |
+
request.response_mode = request.response_mode or self.default_response_mode
|
| 192 |
+
|
| 193 |
+
if request.response_mode not in ('query', 'fragment'):
|
| 194 |
+
log.debug('Overriding invalid response mode %s with %s',
|
| 195 |
+
request.response_mode, self.default_response_mode)
|
| 196 |
+
request.response_mode = self.default_response_mode
|
| 197 |
+
|
| 198 |
+
token_items = token.items()
|
| 199 |
+
|
| 200 |
+
if request.response_type == 'none':
|
| 201 |
+
state = token.get('state', None)
|
| 202 |
+
if state:
|
| 203 |
+
token_items = [('state', state)]
|
| 204 |
+
else:
|
| 205 |
+
token_items = []
|
| 206 |
+
|
| 207 |
+
if request.response_mode == 'query':
|
| 208 |
+
headers['Location'] = add_params_to_uri(
|
| 209 |
+
request.redirect_uri, token_items, fragment=False)
|
| 210 |
+
return headers, body, status
|
| 211 |
+
|
| 212 |
+
if request.response_mode == 'fragment':
|
| 213 |
+
headers['Location'] = add_params_to_uri(
|
| 214 |
+
request.redirect_uri, token_items, fragment=True)
|
| 215 |
+
return headers, body, status
|
| 216 |
+
|
| 217 |
+
raise NotImplementedError(
|
| 218 |
+
'Subclasses must set a valid default_response_mode')
|
| 219 |
+
|
| 220 |
+
def _get_default_headers(self):
|
| 221 |
+
"""Create default headers for grant responses."""
|
| 222 |
+
return {
|
| 223 |
+
'Content-Type': 'application/json',
|
| 224 |
+
'Cache-Control': 'no-store',
|
| 225 |
+
'Pragma': 'no-cache',
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
def _handle_redirects(self, request):
|
| 229 |
+
if request.redirect_uri is not None:
|
| 230 |
+
request.using_default_redirect_uri = False
|
| 231 |
+
log.debug('Using provided redirect_uri %s', request.redirect_uri)
|
| 232 |
+
if not is_absolute_uri(request.redirect_uri):
|
| 233 |
+
raise errors.InvalidRedirectURIError(request=request)
|
| 234 |
+
|
| 235 |
+
# The authorization server MUST verify that the redirection URI
|
| 236 |
+
# to which it will redirect the access token matches a
|
| 237 |
+
# redirection URI registered by the client as described in
|
| 238 |
+
# Section 3.1.2.
|
| 239 |
+
# https://tools.ietf.org/html/rfc6749#section-3.1.2
|
| 240 |
+
if not self.request_validator.validate_redirect_uri(
|
| 241 |
+
request.client_id, request.redirect_uri, request):
|
| 242 |
+
raise errors.MismatchingRedirectURIError(request=request)
|
| 243 |
+
else:
|
| 244 |
+
request.redirect_uri = self.request_validator.get_default_redirect_uri(
|
| 245 |
+
request.client_id, request)
|
| 246 |
+
request.using_default_redirect_uri = True
|
| 247 |
+
log.debug('Using default redirect_uri %s.', request.redirect_uri)
|
| 248 |
+
if not request.redirect_uri:
|
| 249 |
+
raise errors.MissingRedirectURIError(request=request)
|
| 250 |
+
if not is_absolute_uri(request.redirect_uri):
|
| 251 |
+
raise errors.InvalidRedirectURIError(request=request)
|
| 252 |
+
|
| 253 |
+
def _create_cors_headers(self, request):
|
| 254 |
+
"""If CORS is allowed, create the appropriate headers."""
|
| 255 |
+
if 'origin' not in request.headers:
|
| 256 |
+
return {}
|
| 257 |
+
|
| 258 |
+
origin = request.headers['origin']
|
| 259 |
+
if not is_secure_transport(origin):
|
| 260 |
+
log.debug('Origin "%s" is not HTTPS, CORS not allowed.', origin)
|
| 261 |
+
return {}
|
| 262 |
+
elif not self.request_validator.is_origin_allowed(
|
| 263 |
+
request.client_id, origin, request):
|
| 264 |
+
log.debug('Invalid origin "%s", CORS not allowed.', origin)
|
| 265 |
+
return {}
|
| 266 |
+
else:
|
| 267 |
+
log.debug('Valid origin "%s", injecting CORS headers.', origin)
|
| 268 |
+
return {'Access-Control-Allow-Origin': origin}
|