MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / OAuth2Authentication

Class OAuth2Authentication

web/pgadmin/authenticate/oauth2.py:118–774  ·  view source on GitHub ↗

OAuth Authentication Class

Source from the content-addressed store, hash-verified

116
117
118class OAuth2Authentication(BaseAuthentication):
119 """OAuth Authentication Class"""
120
121 LOGOUT_VIEW = OAUTH2_LOGOUT
122
123 oauth_obj = OAuth(Flask(__name__))
124 oauth2_clients = {}
125 oauth2_config = {}
126 email_keys = ['mail', 'email']
127
128 _WORKLOAD_IDENTITY_ASSERTION_TYPE = (
129 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
130 )
131
132 def __init__(self):
133 # Selected provider name (set during authenticate()).
134 # Initializing avoids AttributeError in edge cases/tests.
135 self.oauth2_current_client = None
136
137 for oauth2_config in config.OAUTH2_CONFIG:
138
139 provider_name = oauth2_config.get('OAUTH2_NAME', '<unknown>')
140
141 client_auth_method = oauth2_config.get(
142 'OAUTH2_CLIENT_AUTH_METHOD', 'client_secret'
143 )
144 if not isinstance(client_auth_method, str):
145 client_auth_method = 'client_secret'
146 client_auth_method = client_auth_method.strip().lower()
147 is_workload_identity = (client_auth_method == 'workload_identity')
148
149 OAuth2Authentication.oauth2_config[
150 oauth2_config['OAUTH2_NAME']] = oauth2_config
151
152 # Build client_kwargs with defaults
153 client_kwargs = {
154 'scope': oauth2_config.get(
155 'OAUTH2_SCOPE', 'email profile'),
156 'verify': oauth2_config.get(
157 'OAUTH2_SSL_CERT_VERIFICATION', True)
158 }
159
160 pkce_method = oauth2_config.get('OAUTH2_CHALLENGE_METHOD')
161 pkce_response_type = oauth2_config.get('OAUTH2_RESPONSE_TYPE')
162 pkce_is_configured = any(
163 [
164 pkce_method is not None,
165 pkce_response_type is not None
166 ]
167 )
168
169 raw_client_secret = oauth2_config.get('OAUTH2_CLIENT_SECRET')
170 client_secret_is_empty = (
171 raw_client_secret is None or
172 (isinstance(raw_client_secret, str) and
173 raw_client_secret.strip() == '')
174 )
175

Calls

no outgoing calls