Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Automate Oauth refresh?

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
mailserveroauth2office365
2 Respuestas
3996 Vistas
Avatar
Onno Filippo

The documentation on connecting Microsoft Outlook 365 explains how to set up the initial oauth authentication, but it doesn't explain how to use a renewal token to automate the renewal of access credentials. I'd like to know how I can make this happen, so that we don't need to do manual maintenence.

0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Mejor respuesta

Hi Onno,

In this case, you can try with the scheduled action to refresh the token. Set up a scheduled action or cron job to run the token renewal logic at regular intervals. This ensures that access credentials are automatically renewed before they expire, minimizing the need for manual maintenance. You have to use the Microsoft Graph API, specifically the OAuth 2.0 token endpoint (https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token), to renew the access token using the refresh token. You'll need to send a POST request to this endpoint with the refresh token and other required parameters to obtain a new access token.



Hope this helps.

1
Avatar
Descartar
Avatar
Lukas Weber
Mejor respuesta

concerning Office365 and OAuth2 work flow: when Odoo alread has a refresh-token, getting (= refreshing) the access-token is described here

https//learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow@refresh-the-access-token

Now, the Odoo Microsoft Outlook Module (for outgoing mail servers) misses in its implementation, that refreshing the Access-token via the oauth2/v2.0/token Endpoint also delivers an updated refresh-token (have a look at the Microsoft Identity Platform Learn link above).

So in fact, Odoo always uses the same Refresh-Token in the Microsoft Outlook Module, once we got this Token via the "Connect your Outlook Account" on the Outgoing Mailserver Settings Page. In EntraID (Azure) this token has a default lifespan of 3 months, and it can be set to maximum of 12 months.

Thats why the problem with "The refresh token has expired due to inactivity" occurs when using the Microsoft Outlook Module in Odoo.

When inspecting the correspondig code in Odoo e.g. for V14 in odoo/addons/microsoft_outlook/models/microsoft_outlook_mixin.py:_generate_outlook_oauth2_string(), we have there:

(

self.microsoft_outlook_access_token,

self.microsoft_outlook_access_token_expiration,

) = self._fetch_outlook_access_token(self.microsoft_outlook_refresh_token)

And in _fetch_outlook_access_token():

response = self._fetch_outlook_token('refresh_token', refresh_token=refresh_token)

return (

response['access_token'],

int(time.time()) + response['expires_in'],

)

But the response from _fetch_outlook_token() above returns back also an updated refresh_token in the response: response['refresh_token'].

So all we need to do is to overwrrite _fetch_outlook_access_token() with:

response = self._fetch_outlook_token('refresh_token', refresh_token=refresh_token)

return (

response['access_token'],

response['refresh_token'],

int(time.time()) + response['expires_in'],

)

and _generate_outlook_oauth2_string() with:

(

self.microsoft_outlook_access_token,

self.microsoft_outlook_refresh_token,

self.microsoft_outlook_access_token_expiration,

) = self._fetch_outlook_access_token(self.microsoft_outlook_refresh_token)

This updates the refresh-token every time when trying to send an email and the access-token of the outgoing mail server has expired. Now if you want to update the refresh-token independently of sending emails, you would need to create a cron job on the ir.mail.server model with an action like this one:

@api.model

def _update_refresh_token(self):

server = self.search([('use_microsoft_outlook_service', '!=', False)]) or False

server = server[0] if server else False

if server and server.microsoft_outlook_refresh_token:

(

server.microsoft_outlook_access_token,

server.microsoft_outlook_refresh_token,

server.microsoft_outlook_access_token_expiration,

) = server._fetch_outlook_access_token(server.microsoft_outlook_refresh_token)

_logger.info(

'Microsoft Outlook, Outgoing Mailserver '%s': OAuth Refresh-Token Updated via Cron-Job',

(server.name))

return True

In the Python Code of the Cron Job for the model "ir.mail.server" you would then write:

model.._update_refresh_token()

By the way: above overwrites of _fetch_outlook_access_token() and _generate_outlook_oauth2_string() automatically updates the refresh-token also for incoming_imap mail servers when fetching email. Fetching email is already done regurarly by a cron job in Odoo.

0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
version 14 error conecting office 365
mailserver office365
Avatar
0
abr 21
3321
fetchmail_outlook & microsoft_outlook modules error
email mailserver office365
Avatar
Avatar
1
dic 22
3947
Mail Setup for Odoo 14
mail mailserver office365
Avatar
0
oct 21
3435
Is OAuth2 supported in the Odoo 18 Community Edition?
oauth2
Avatar
Avatar
Avatar
2
sept 25
3171
Changing the default System Notifications Email in Odoo 17 Resuelto
mailserver
Avatar
Avatar
2
nov 24
7165
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now