You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. from odoo import models, fields, api
  2. from .. import random_tokens
  3. try:
  4. from jwcrypto import jwk
  5. except ImportError:
  6. pass
  7. class ConfigParameter(models.Model):
  8. _inherit = "ir.config_parameter"
  9. @api.model
  10. def openid_init_keys(self):
  11. keys = {
  12. "galicea_openid_connect.authorization_code_jwk": lambda: jwk.JWK.generate(
  13. kty="oct",
  14. size=256,
  15. kid=random_tokens.alpha_numeric(16),
  16. use="sig",
  17. alg="HS256",
  18. ).export(),
  19. "galicea_openid_connect.id_token_jwk": lambda: jwk.JWK.generate(
  20. kty="RSA",
  21. size=2054,
  22. kid=random_tokens.alpha_numeric(16),
  23. use="sig",
  24. alg="RS256",
  25. ).export(),
  26. }
  27. for key, gen in iter(keys.items()):
  28. if not self.search([("key", "=", key)]):
  29. self.create(
  30. {
  31. "key": key,
  32. "value": gen(),
  33. "group_ids": [(4, self.env.ref("base.group_erp_manager").id)],
  34. }
  35. )