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.

28 lines
925 B

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: \
  14. jwk.JWK.generate(kty='oct', size=256, kid=random_tokens.alpha_numeric(16), use='sig', alg='HS256').export(),
  15. 'galicea_openid_connect.id_token_jwk': lambda: \
  16. jwk.JWK.generate(kty='RSA', size=2054, kid=random_tokens.alpha_numeric(16), use='sig', alg='RS256').export()
  17. }
  18. for key, gen in iter(keys.items()):
  19. if not self.search([('key', '=', key)]):
  20. self.create({
  21. 'key': key,
  22. 'value': gen(),
  23. 'group_ids': [(4, self.env.ref('base.group_erp_manager').id)]
  24. })