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.

41 lines
1.1 KiB

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