In this blog we will explain how to generate access token in odoo for each user step by step , so
1- create new class which is inherits res.users class
2- create new char field which will contain the token , and it must be compute field
3- create function to generate the token
as bellow
from odoo import models, fields, api, _
import hashlib
import hmac
import base64
import string
import math, random
from passlib import pwd, hash
class ResUsers(models.Model):
_inherit = 'res.users'
access_token = fields.Char(string="Access Token", readonly=True, compute='generate_access_token')
def generate_access_token(self):
for rec in self:
token = ""
# first way
# pre_token = rec.name+rec.login
# token = hash.pbkdf2_sha512.hash(pre_token)
# second way
hash_object = hashlib.sha256(rec.password.encode())
token = hash_object.hexdigest()
rec.sudo().write({'access_token': token})
No comments:
Post a Comment