|  | @ -20,12 +20,15 @@ | 
			
		
	
		
		
			
				
					|  |  | # |  |  | # | 
			
		
	
		
		
			
				
					|  |  | ############################################################################### |  |  | ############################################################################### | 
			
		
	
		
		
			
				
					|  |  | import json |  |  | import json | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import logging | 
			
		
	
		
		
			
				
					|  |  | import requests |  |  | import requests | 
			
		
	
		
		
			
				
					|  |  | from werkzeug import urls |  |  | from werkzeug import urls | 
			
		
	
		
		
			
				
					|  |  | from odoo import fields, models, _ |  |  | from odoo import fields, models, _ | 
			
		
	
		
		
			
				
					|  |  | from odoo.exceptions import UserError |  |  | from odoo.exceptions import UserError | 
			
		
	
		
		
			
				
					|  |  | from odoo.http import request |  |  | from odoo.http import request | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | _logger = logging.getLogger(__name__) | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | class ResConfigSettings(models.TransientModel): |  |  | class ResConfigSettings(models.TransientModel): | 
			
		
	
		
		
			
				
					|  |  |     """ |  |  |     """ | 
			
		
	
	
		
		
			
				
					|  | @ -47,6 +50,10 @@ class ResConfigSettings(models.TransientModel): | 
			
		
	
		
		
			
				
					|  |  |     onedrive_access_token = fields.Char( |  |  |     onedrive_access_token = fields.Char( | 
			
		
	
		
		
			
				
					|  |  |         string='Onedrive Access Token', |  |  |         string='Onedrive Access Token', | 
			
		
	
		
		
			
				
					|  |  |         help="Access Token for authenticating with OneDrive API") |  |  |         help="Access Token for authenticating with OneDrive API") | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     onedrive_tenant_id = fields.Char( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         string="Onedrive Tenant Id", | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         config_parameter='onedrive_integration_odoo.tenant_id', | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         help="Director (tenant) id for accessing OneDrive API") | 
			
		
	
		
		
			
				
					|  |  |     onedrive_refresh_token = fields.Char( |  |  |     onedrive_refresh_token = fields.Char( | 
			
		
	
		
		
			
				
					|  |  |         string='Onedrive Refresh Token', |  |  |         string='Onedrive Refresh Token', | 
			
		
	
		
		
			
				
					|  |  |         help="Refresh Token for refreshing the access token") |  |  |         help="Refresh Token for refreshing the access token") | 
			
		
	
	
		
		
			
				
					|  | @ -72,12 +79,16 @@ class ResConfigSettings(models.TransientModel): | 
			
		
	
		
		
			
				
					|  |  |             'redirect_uri': request.env['ir.config_parameter'].get_param( |  |  |             'redirect_uri': request.env['ir.config_parameter'].get_param( | 
			
		
	
		
		
			
				
					|  |  |                 'web.base.url') + '/onedrive/authentication' |  |  |                 'web.base.url') + '/onedrive/authentication' | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         tenant_id = self.env['ir.config_parameter'].get_param( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             'onedrive_integration_odoo.tenant_id', '') | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         res = requests.post( |  |  |         res = requests.post( | 
			
		
	
		
		
			
				
					
					|  |  |             "https://login.microsoftonline.com/common/oauth2/v2.0/token", |  |  |             f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token", | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             data=data, |  |  |             data=data, | 
			
		
	
		
		
			
				
					|  |  |             headers={"content-type": "application/x-www-form-urlencoded"}) |  |  |             headers={"content-type": "application/x-www-form-urlencoded"}) | 
			
		
	
		
		
			
				
					|  |  |         response = res.content and res.json() or {} |  |  |         response = res.content and res.json() or {} | 
			
		
	
		
		
			
				
					|  |  |         if 'error' in response: |  |  |         if 'error' in response: | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             _logger.warning(response) | 
			
		
	
		
		
			
				
					|  |  |             raise UserError(_("Error '%s': Please check the credentials.", |  |  |             raise UserError(_("Error '%s': Please check the credentials.", | 
			
		
	
		
		
			
				
					|  |  |                               response['error'])) |  |  |                               response['error'])) | 
			
		
	
		
		
			
				
					|  |  |         else: |  |  |         else: | 
			
		
	
	
		
		
			
				
					|  | 
 |