oidc.py 25 KB

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