oidc.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. # Copyright 2020 Quentin Gliech
  2. # Copyright 2020-2021 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from collections import Counter
  16. from typing import Any, Collection, Iterable, List, Mapping, Optional, Tuple, Type
  17. import attr
  18. from synapse.config._util import validate_config
  19. from synapse.config.sso import SsoAttributeRequirement
  20. from synapse.types import JsonDict
  21. from synapse.util.module_loader import load_module
  22. from synapse.util.stringutils import parse_and_validate_mxc_uri
  23. from ..util.check_dependencies import DependencyException, check_requirements
  24. from ._base import Config, ConfigError, read_file
  25. DEFAULT_USER_MAPPING_PROVIDER = "synapse.handlers.oidc.JinjaOidcMappingProvider"
  26. # The module that JinjaOidcMappingProvider is in was renamed, we want to
  27. # transparently handle both the same.
  28. LEGACY_USER_MAPPING_PROVIDER = "synapse.handlers.oidc_handler.JinjaOidcMappingProvider"
  29. class OIDCConfig(Config):
  30. section = "oidc"
  31. def read_config(self, config, **kwargs) -> None:
  32. self.oidc_providers = tuple(_parse_oidc_provider_configs(config))
  33. if not self.oidc_providers:
  34. return
  35. try:
  36. check_requirements("oidc")
  37. except DependencyException as e:
  38. raise ConfigError(
  39. e.message # noqa: B306, DependencyException.message is a property
  40. ) from e
  41. # check we don't have any duplicate idp_ids now. (The SSO handler will also
  42. # check for duplicates when the REST listeners get registered, but that happens
  43. # after synapse has forked so doesn't give nice errors.)
  44. c = Counter([i.idp_id for i in self.oidc_providers])
  45. for idp_id, count in c.items():
  46. if count > 1:
  47. raise ConfigError(
  48. "Multiple OIDC providers have the idp_id %r." % idp_id
  49. )
  50. public_baseurl = self.root.server.public_baseurl
  51. self.oidc_callback_url = public_baseurl + "_synapse/client/oidc/callback"
  52. @property
  53. def oidc_enabled(self) -> bool:
  54. # OIDC is enabled if we have a provider
  55. return bool(self.oidc_providers)
  56. def generate_config_section(self, config_dir_path, server_name, **kwargs) -> str:
  57. return """\
  58. # List of OpenID Connect (OIDC) / OAuth 2.0 identity providers, for registration
  59. # and login.
  60. #
  61. # Options for each entry include:
  62. #
  63. # idp_id: a unique identifier for this identity provider. Used internally
  64. # by Synapse; should be a single word such as 'github'.
  65. #
  66. # Note that, if this is changed, users authenticating via that provider
  67. # will no longer be recognised as the same user!
  68. #
  69. # (Use "oidc" here if you are migrating from an old "oidc_config"
  70. # configuration.)
  71. #
  72. # idp_name: A user-facing name for this identity provider, which is used to
  73. # offer the user a choice of login mechanisms.
  74. #
  75. # idp_icon: An optional icon for this identity provider, which is presented
  76. # by clients and Synapse's own IdP picker page. If given, must be an
  77. # MXC URI of the format mxc://<server-name>/<media-id>. (An easy way to
  78. # obtain such an MXC URI is to upload an image to an (unencrypted) room
  79. # and then copy the "url" from the source of the event.)
  80. #
  81. # idp_brand: An optional brand for this identity provider, allowing clients
  82. # to style the login flow according to the identity provider in question.
  83. # See the spec for possible options here.
  84. #
  85. # discover: set to 'false' to disable the use of the OIDC discovery mechanism
  86. # to discover endpoints. Defaults to true.
  87. #
  88. # issuer: Required. The OIDC issuer. Used to validate tokens and (if discovery
  89. # is enabled) to discover the provider's endpoints.
  90. #
  91. # client_id: Required. oauth2 client id to use.
  92. #
  93. # client_secret: oauth2 client secret to use. May be omitted if
  94. # client_secret_jwt_key is given, or if client_auth_method is 'none'.
  95. #
  96. # client_secret_jwt_key: Alternative to client_secret: details of a key used
  97. # to create a JSON Web Token to be used as an OAuth2 client secret. If
  98. # given, must be a dictionary with the following properties:
  99. #
  100. # key: a pem-encoded signing key. Must be a suitable key for the
  101. # algorithm specified. Required unless 'key_file' is given.
  102. #
  103. # key_file: the path to file containing a pem-encoded signing key file.
  104. # Required unless 'key' is given.
  105. #
  106. # jwt_header: a dictionary giving properties to include in the JWT
  107. # header. Must include the key 'alg', giving the algorithm used to
  108. # sign the JWT, such as "ES256", using the JWA identifiers in
  109. # RFC7518.
  110. #
  111. # jwt_payload: an optional dictionary giving properties to include in
  112. # the JWT payload. Normally this should include an 'iss' key.
  113. #
  114. # client_auth_method: auth method to use when exchanging the token. Valid
  115. # values are 'client_secret_basic' (default), 'client_secret_post' and
  116. # 'none'.
  117. #
  118. # scopes: list of scopes to request. This should normally include the "openid"
  119. # scope. Defaults to ["openid"].
  120. #
  121. # authorization_endpoint: the oauth2 authorization endpoint. Required if
  122. # provider discovery is disabled.
  123. #
  124. # token_endpoint: the oauth2 token endpoint. Required if provider discovery is
  125. # disabled.
  126. #
  127. # userinfo_endpoint: the OIDC userinfo endpoint. Required if discovery is
  128. # disabled and the 'openid' scope is not requested.
  129. #
  130. # jwks_uri: URI where to fetch the JWKS. Required if discovery is disabled and
  131. # the 'openid' scope is used.
  132. #
  133. # skip_verification: set to 'true' to skip metadata verification. Use this if
  134. # you are connecting to a provider that is not OpenID Connect compliant.
  135. # Defaults to false. Avoid this in production.
  136. #
  137. # user_profile_method: Whether to fetch the user profile from the userinfo
  138. # endpoint, or to rely on the data returned in the id_token from the
  139. # token_endpoint.
  140. #
  141. # Valid values are: 'auto' or 'userinfo_endpoint'.
  142. #
  143. # Defaults to 'auto', which uses the userinfo endpoint if 'openid' is
  144. # not included in 'scopes'. Set to 'userinfo_endpoint' to always use the
  145. # userinfo endpoint.
  146. #
  147. # allow_existing_users: set to 'true' to allow a user logging in via OIDC to
  148. # match a pre-existing account instead of failing. This could be used if
  149. # switching from password logins to OIDC. Defaults to false.
  150. #
  151. # user_mapping_provider: Configuration for how attributes returned from a OIDC
  152. # provider are mapped onto a matrix user. This setting has the following
  153. # sub-properties:
  154. #
  155. # module: The class name of a custom mapping module. Default is
  156. # {mapping_provider!r}.
  157. # See https://matrix-org.github.io/synapse/latest/sso_mapping_providers.html#openid-mapping-providers
  158. # for information on implementing a custom mapping provider.
  159. #
  160. # config: Configuration for the mapping provider module. This section will
  161. # be passed as a Python dictionary to the user mapping provider
  162. # module's `parse_config` method.
  163. #
  164. # For the default provider, the following settings are available:
  165. #
  166. # subject_claim: name of the claim containing a unique identifier
  167. # for the user. Defaults to 'sub', which OpenID Connect
  168. # compliant providers should provide.
  169. #
  170. # localpart_template: Jinja2 template for the localpart of the MXID.
  171. # If this is not set, the user will be prompted to choose their
  172. # own username (see the documentation for the
  173. # 'sso_auth_account_details.html' template). This template can
  174. # use the 'localpart_from_email' filter.
  175. #
  176. # confirm_localpart: Whether to prompt the user to validate (or
  177. # change) the generated localpart (see the documentation for the
  178. # 'sso_auth_account_details.html' template), instead of
  179. # registering the account right away.
  180. #
  181. # display_name_template: Jinja2 template for the display name to set
  182. # on first login. If unset, no displayname will be set.
  183. #
  184. # email_template: Jinja2 template for the email address of the user.
  185. # If unset, no email address will be added to the account.
  186. #
  187. # extra_attributes: a map of Jinja2 templates for extra attributes
  188. # to send back to the client during login.
  189. # Note that these are non-standard and clients will ignore them
  190. # without modifications.
  191. #
  192. # When rendering, the Jinja2 templates are given a 'user' variable,
  193. # which is set to the claims returned by the UserInfo Endpoint and/or
  194. # in the ID Token.
  195. #
  196. # It is possible to configure Synapse to only allow logins if certain attributes
  197. # match particular values in the OIDC userinfo. The requirements can be listed under
  198. # `attribute_requirements` as shown below. All of the listed attributes must
  199. # match for the login to be permitted. Additional attributes can be added to
  200. # userinfo by expanding the `scopes` section of the OIDC config to retrieve
  201. # additional information from the OIDC provider.
  202. #
  203. # If the OIDC claim is a list, then the attribute must match any value in the list.
  204. # Otherwise, it must exactly match the value of the claim. Using the example
  205. # below, the `family_name` claim MUST be "Stephensson", but the `groups`
  206. # claim MUST contain "admin".
  207. #
  208. # attribute_requirements:
  209. # - attribute: family_name
  210. # value: "Stephensson"
  211. # - attribute: groups
  212. # value: "admin"
  213. #
  214. # See https://matrix-org.github.io/synapse/latest/openid.html
  215. # for information on how to configure these options.
  216. #
  217. # For backwards compatibility, it is also possible to configure a single OIDC
  218. # provider via an 'oidc_config' setting. This is now deprecated and admins are
  219. # advised to migrate to the 'oidc_providers' format. (When doing that migration,
  220. # use 'oidc' for the idp_id to ensure that existing users continue to be
  221. # recognised.)
  222. #
  223. oidc_providers:
  224. # Generic example
  225. #
  226. #- idp_id: my_idp
  227. # idp_name: "My OpenID provider"
  228. # idp_icon: "mxc://example.com/mediaid"
  229. # discover: false
  230. # issuer: "https://accounts.example.com/"
  231. # client_id: "provided-by-your-issuer"
  232. # client_secret: "provided-by-your-issuer"
  233. # client_auth_method: client_secret_post
  234. # scopes: ["openid", "profile"]
  235. # authorization_endpoint: "https://accounts.example.com/oauth2/auth"
  236. # token_endpoint: "https://accounts.example.com/oauth2/token"
  237. # userinfo_endpoint: "https://accounts.example.com/userinfo"
  238. # jwks_uri: "https://accounts.example.com/.well-known/jwks.json"
  239. # skip_verification: true
  240. # user_mapping_provider:
  241. # config:
  242. # subject_claim: "id"
  243. # localpart_template: "{{{{ user.login }}}}"
  244. # display_name_template: "{{{{ user.name }}}}"
  245. # email_template: "{{{{ user.email }}}}"
  246. # attribute_requirements:
  247. # - attribute: userGroup
  248. # value: "synapseUsers"
  249. """.format(
  250. mapping_provider=DEFAULT_USER_MAPPING_PROVIDER
  251. )
  252. # jsonschema definition of the configuration settings for an oidc identity provider
  253. OIDC_PROVIDER_CONFIG_SCHEMA = {
  254. "type": "object",
  255. "required": ["issuer", "client_id"],
  256. "properties": {
  257. "idp_id": {
  258. "type": "string",
  259. "minLength": 1,
  260. # MSC2858 allows a maxlen of 255, but we prefix with "oidc-"
  261. "maxLength": 250,
  262. "pattern": "^[A-Za-z0-9._~-]+$",
  263. },
  264. "idp_name": {"type": "string"},
  265. "idp_icon": {"type": "string"},
  266. "idp_brand": {
  267. "type": "string",
  268. "minLength": 1,
  269. "maxLength": 255,
  270. "pattern": "^[a-z][a-z0-9_.-]*$",
  271. },
  272. "discover": {"type": "boolean"},
  273. "issuer": {"type": "string"},
  274. "client_id": {"type": "string"},
  275. "client_secret": {"type": "string"},
  276. "client_secret_jwt_key": {
  277. "type": "object",
  278. "required": ["jwt_header"],
  279. "oneOf": [
  280. {"required": ["key"]},
  281. {"required": ["key_file"]},
  282. ],
  283. "properties": {
  284. "key": {"type": "string"},
  285. "key_file": {"type": "string"},
  286. "jwt_header": {
  287. "type": "object",
  288. "required": ["alg"],
  289. "properties": {
  290. "alg": {"type": "string"},
  291. },
  292. "additionalProperties": {"type": "string"},
  293. },
  294. "jwt_payload": {
  295. "type": "object",
  296. "additionalProperties": {"type": "string"},
  297. },
  298. },
  299. },
  300. "client_auth_method": {
  301. "type": "string",
  302. # the following list is the same as the keys of
  303. # authlib.oauth2.auth.ClientAuth.DEFAULT_AUTH_METHODS. We inline it
  304. # to avoid importing authlib here.
  305. "enum": ["client_secret_basic", "client_secret_post", "none"],
  306. },
  307. "scopes": {"type": "array", "items": {"type": "string"}},
  308. "authorization_endpoint": {"type": "string"},
  309. "token_endpoint": {"type": "string"},
  310. "userinfo_endpoint": {"type": "string"},
  311. "jwks_uri": {"type": "string"},
  312. "skip_verification": {"type": "boolean"},
  313. "user_profile_method": {
  314. "type": "string",
  315. "enum": ["auto", "userinfo_endpoint"],
  316. },
  317. "allow_existing_users": {"type": "boolean"},
  318. "user_mapping_provider": {"type": ["object", "null"]},
  319. "attribute_requirements": {
  320. "type": "array",
  321. "items": SsoAttributeRequirement.JSON_SCHEMA,
  322. },
  323. },
  324. }
  325. # the same as OIDC_PROVIDER_CONFIG_SCHEMA, but with compulsory idp_id and idp_name
  326. OIDC_PROVIDER_CONFIG_WITH_ID_SCHEMA = {
  327. "allOf": [OIDC_PROVIDER_CONFIG_SCHEMA, {"required": ["idp_id", "idp_name"]}]
  328. }
  329. # the `oidc_providers` list can either be None (as it is in the default config), or
  330. # a list of provider configs, each of which requires an explicit ID and name.
  331. OIDC_PROVIDER_LIST_SCHEMA = {
  332. "oneOf": [
  333. {"type": "null"},
  334. {"type": "array", "items": OIDC_PROVIDER_CONFIG_WITH_ID_SCHEMA},
  335. ]
  336. }
  337. # the `oidc_config` setting can either be None (which it used to be in the default
  338. # config), or an object. If an object, it is ignored unless it has an "enabled: True"
  339. # property.
  340. #
  341. # It's *possible* to represent this with jsonschema, but the resultant errors aren't
  342. # particularly clear, so we just check for either an object or a null here, and do
  343. # additional checks in the code.
  344. OIDC_CONFIG_SCHEMA = {"oneOf": [{"type": "null"}, {"type": "object"}]}
  345. # the top-level schema can contain an "oidc_config" and/or an "oidc_providers".
  346. MAIN_CONFIG_SCHEMA = {
  347. "type": "object",
  348. "properties": {
  349. "oidc_config": OIDC_CONFIG_SCHEMA,
  350. "oidc_providers": OIDC_PROVIDER_LIST_SCHEMA,
  351. },
  352. }
  353. def _parse_oidc_provider_configs(config: JsonDict) -> Iterable["OidcProviderConfig"]:
  354. """extract and parse the OIDC provider configs from the config dict
  355. The configuration may contain either a single `oidc_config` object with an
  356. `enabled: True` property, or a list of provider configurations under
  357. `oidc_providers`, *or both*.
  358. Returns a generator which yields the OidcProviderConfig objects
  359. """
  360. validate_config(MAIN_CONFIG_SCHEMA, config, ())
  361. for i, p in enumerate(config.get("oidc_providers") or []):
  362. yield _parse_oidc_config_dict(p, ("oidc_providers", "<item %i>" % (i,)))
  363. # for backwards-compatibility, it is also possible to provide a single "oidc_config"
  364. # object with an "enabled: True" property.
  365. oidc_config = config.get("oidc_config")
  366. if oidc_config and oidc_config.get("enabled", False):
  367. # MAIN_CONFIG_SCHEMA checks that `oidc_config` is an object, but not that
  368. # it matches OIDC_PROVIDER_CONFIG_SCHEMA (see the comments on OIDC_CONFIG_SCHEMA
  369. # above), so now we need to validate it.
  370. validate_config(OIDC_PROVIDER_CONFIG_SCHEMA, oidc_config, ("oidc_config",))
  371. yield _parse_oidc_config_dict(oidc_config, ("oidc_config",))
  372. def _parse_oidc_config_dict(
  373. oidc_config: JsonDict, config_path: Tuple[str, ...]
  374. ) -> "OidcProviderConfig":
  375. """Take the configuration dict and parse it into an OidcProviderConfig
  376. Raises:
  377. ConfigError if the configuration is malformed.
  378. """
  379. ump_config = oidc_config.get("user_mapping_provider", {})
  380. ump_config.setdefault("module", DEFAULT_USER_MAPPING_PROVIDER)
  381. if ump_config.get("module") == LEGACY_USER_MAPPING_PROVIDER:
  382. ump_config["module"] = DEFAULT_USER_MAPPING_PROVIDER
  383. ump_config.setdefault("config", {})
  384. (
  385. user_mapping_provider_class,
  386. user_mapping_provider_config,
  387. ) = load_module(ump_config, config_path + ("user_mapping_provider",))
  388. # Ensure loaded user mapping module has defined all necessary methods
  389. required_methods = [
  390. "get_remote_user_id",
  391. "map_user_attributes",
  392. ]
  393. missing_methods = [
  394. method
  395. for method in required_methods
  396. if not hasattr(user_mapping_provider_class, method)
  397. ]
  398. if missing_methods:
  399. raise ConfigError(
  400. "Class %s is missing required "
  401. "methods: %s"
  402. % (
  403. user_mapping_provider_class,
  404. ", ".join(missing_methods),
  405. ),
  406. config_path + ("user_mapping_provider", "module"),
  407. )
  408. idp_id = oidc_config.get("idp_id", "oidc")
  409. # prefix the given IDP with a prefix specific to the SSO mechanism, to avoid
  410. # clashes with other mechs (such as SAML, CAS).
  411. #
  412. # We allow "oidc" as an exception so that people migrating from old-style
  413. # "oidc_config" format (which has long used "oidc" as its idp_id) can migrate to
  414. # a new-style "oidc_providers" entry without changing the idp_id for their provider
  415. # (and thereby invalidating their user_external_ids data).
  416. if idp_id != "oidc":
  417. idp_id = "oidc-" + idp_id
  418. # MSC2858 also specifies that the idp_icon must be a valid MXC uri
  419. idp_icon = oidc_config.get("idp_icon")
  420. if idp_icon is not None:
  421. try:
  422. parse_and_validate_mxc_uri(idp_icon)
  423. except ValueError as e:
  424. raise ConfigError(
  425. "idp_icon must be a valid MXC URI", config_path + ("idp_icon",)
  426. ) from e
  427. client_secret_jwt_key_config = oidc_config.get("client_secret_jwt_key")
  428. client_secret_jwt_key: Optional[OidcProviderClientSecretJwtKey] = None
  429. if client_secret_jwt_key_config is not None:
  430. keyfile = client_secret_jwt_key_config.get("key_file")
  431. if keyfile:
  432. key = read_file(keyfile, config_path + ("client_secret_jwt_key",))
  433. else:
  434. key = client_secret_jwt_key_config["key"]
  435. client_secret_jwt_key = OidcProviderClientSecretJwtKey(
  436. key=key,
  437. jwt_header=client_secret_jwt_key_config["jwt_header"],
  438. jwt_payload=client_secret_jwt_key_config.get("jwt_payload", {}),
  439. )
  440. # parse attribute_requirements from config (list of dicts) into a list of SsoAttributeRequirement
  441. attribute_requirements = [
  442. SsoAttributeRequirement(**x)
  443. for x in oidc_config.get("attribute_requirements", [])
  444. ]
  445. return OidcProviderConfig(
  446. idp_id=idp_id,
  447. idp_name=oidc_config.get("idp_name", "OIDC"),
  448. idp_icon=idp_icon,
  449. idp_brand=oidc_config.get("idp_brand"),
  450. discover=oidc_config.get("discover", True),
  451. issuer=oidc_config["issuer"],
  452. client_id=oidc_config["client_id"],
  453. client_secret=oidc_config.get("client_secret"),
  454. client_secret_jwt_key=client_secret_jwt_key,
  455. client_auth_method=oidc_config.get("client_auth_method", "client_secret_basic"),
  456. scopes=oidc_config.get("scopes", ["openid"]),
  457. authorization_endpoint=oidc_config.get("authorization_endpoint"),
  458. token_endpoint=oidc_config.get("token_endpoint"),
  459. userinfo_endpoint=oidc_config.get("userinfo_endpoint"),
  460. jwks_uri=oidc_config.get("jwks_uri"),
  461. skip_verification=oidc_config.get("skip_verification", False),
  462. user_profile_method=oidc_config.get("user_profile_method", "auto"),
  463. allow_existing_users=oidc_config.get("allow_existing_users", False),
  464. user_mapping_provider_class=user_mapping_provider_class,
  465. user_mapping_provider_config=user_mapping_provider_config,
  466. attribute_requirements=attribute_requirements,
  467. )
  468. @attr.s(slots=True, frozen=True, auto_attribs=True)
  469. class OidcProviderClientSecretJwtKey:
  470. # a pem-encoded signing key
  471. key: str
  472. # properties to include in the JWT header
  473. jwt_header: Mapping[str, str]
  474. # properties to include in the JWT payload.
  475. jwt_payload: Mapping[str, str]
  476. @attr.s(slots=True, frozen=True, auto_attribs=True)
  477. class OidcProviderConfig:
  478. # a unique identifier for this identity provider. Used in the 'user_external_ids'
  479. # table, as well as the query/path parameter used in the login protocol.
  480. idp_id: str
  481. # user-facing name for this identity provider.
  482. idp_name: str
  483. # Optional MXC URI for icon for this IdP.
  484. idp_icon: Optional[str]
  485. # Optional brand identifier for this IdP.
  486. idp_brand: Optional[str]
  487. # whether the OIDC discovery mechanism is used to discover endpoints
  488. discover: bool
  489. # the OIDC issuer. Used to validate tokens and (if discovery is enabled) to
  490. # discover the provider's endpoints.
  491. issuer: str
  492. # oauth2 client id to use
  493. client_id: str
  494. # oauth2 client secret to use. if `None`, use client_secret_jwt_key to generate
  495. # a secret.
  496. client_secret: Optional[str]
  497. # key to use to construct a JWT to use as a client secret. May be `None` if
  498. # `client_secret` is set.
  499. client_secret_jwt_key: Optional[OidcProviderClientSecretJwtKey]
  500. # auth method to use when exchanging the token.
  501. # Valid values are 'client_secret_basic', 'client_secret_post' and
  502. # 'none'.
  503. client_auth_method: str
  504. # list of scopes to request
  505. scopes: Collection[str]
  506. # the oauth2 authorization endpoint. Required if discovery is disabled.
  507. authorization_endpoint: Optional[str]
  508. # the oauth2 token endpoint. Required if discovery is disabled.
  509. token_endpoint: Optional[str]
  510. # the OIDC userinfo endpoint. Required if discovery is disabled and the
  511. # "openid" scope is not requested.
  512. userinfo_endpoint: Optional[str]
  513. # URI where to fetch the JWKS. Required if discovery is disabled and the
  514. # "openid" scope is used.
  515. jwks_uri: Optional[str]
  516. # Whether to skip metadata verification
  517. skip_verification: bool
  518. # Whether to fetch the user profile from the userinfo endpoint. Valid
  519. # values are: "auto" or "userinfo_endpoint".
  520. user_profile_method: str
  521. # whether to allow a user logging in via OIDC to match a pre-existing account
  522. # instead of failing
  523. allow_existing_users: bool
  524. # the class of the user mapping provider
  525. user_mapping_provider_class: Type
  526. # the config of the user mapping provider
  527. user_mapping_provider_config: Any
  528. # required attributes to require in userinfo to allow login/registration
  529. attribute_requirements: List[SsoAttributeRequirement]