MCPcopy Create free account
hub / github.com/authlib/authlib / ClientAuthentication

Class ClientAuthentication

authlib/oauth2/rfc6749/authenticate_client.py:24–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22
23
24class ClientAuthentication:
25 def __init__(self, query_client):
26 self.query_client = query_client
27 self._methods = {
28 "none": authenticate_none,
29 "client_secret_basic": authenticate_client_secret_basic,
30 "client_secret_post": authenticate_client_secret_post,
31 }
32
33 def register(self, method, func):
34 self._methods[method] = func
35
36 def authenticate(self, request, methods, endpoint):
37 for method in methods:
38 func = self._methods[method]
39 client = func(self.query_client, request)
40 if not client or not client.check_endpoint_auth_method(method, endpoint):
41 continue
42
43 # RFC 6749 §3.2.1: confidential clients MUST authenticate.
44 if method == "none" and not client.check_endpoint_auth_method(
45 "none", "token"
46 ):
47 continue
48
49 request.auth_method = method
50 return client
51
52 if "client_secret_basic" in methods:
53 raise InvalidClientError(
54 status_code=401,
55 description=f"The client cannot authenticate with methods: {methods}",
56 )
57 raise InvalidClientError(
58 description=f"The client cannot authenticate with methods: {methods}",
59 )
60
61 def __call__(self, request, methods, endpoint="token"):
62 return self.authenticate(request, methods, endpoint)
63
64
65def authenticate_client_secret_basic(query_client, request):

Callers 2

authenticate_clientMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected