Next Step - mechwarrior82/eve-online-odoo-integration GitHub Wiki
Fantastic! Now that we've set up the structure for our integration_service
folder and configured our environment variables, let's proceed with the next steps:
Step-by-Step Guide to Continue Development
Step 1: Finalize the Flask Server Setup
-
Ensure All Files Are in Place:
- Verify that your
integration_service
folder contains all the necessary files and subdirectories (as we've discussed).
- Verify that your
-
Create the
.env
File:- In the root of your project, create a
.env
file and add your OAuth credentials:EVE_CLIENT_ID=your_client_id EVE_CLIENT_SECRET=your_client_secret EVE_REDIRECT_URI=your_redirect_uri
- In the root of your project, create a
-
Install Dependencies:
- Make sure you have
Flask
,requests
, andpython-dotenv
installed. If you haven't already installed them, run:pip install Flask requests python-dotenv
- Make sure you have
-
Run the Server:
- Navigate to your project directory and run the Flask server:
python integration_service/app.py
- Open
http://localhost:5000/
in your browser to start the OAuth flow and test the login functionality.
- Navigate to your project directory and run the Flask server:
Step 2: Implement Communication with Odoo
-
Create Endpoints in Odoo to Receive User Data:
- Next, we need to set up the custom Odoo module that will handle the user data sent from the Flask server.
- Create a new folder for your custom Odoo module (e.g.,
odoo_eve_integration
) and structure it as follows:odoo_eve_integration/ βββ __init__.py βββ __manifest__.py βββ controllers/ β βββ __init__.py β βββ main.py βββ models/ β βββ __init__.py β βββ eve_user.py
-
Define the Module Manifest: manifest.py:
{ 'name': 'Eve Online Integration', 'version': '1.0', 'summary': 'Integration with Eve Online for user authentication', 'depends': ['base'], 'data': [], 'installable': True, 'application': True, }
-
Create a Controller to Handle Incoming Data: controllers/main.py:
from odoo import http from odoo.http import request class EveController(http.Controller): @http.route('/eve/auth', type='json', auth='public', methods=['POST']) def eve_auth(self, **kwargs): # Process the received data and create or update user records character_id = kwargs.get('character_id') character_name = kwargs.get('character_name') email = kwargs.get('email') # Create or update the user in Odoo user = request.env['res.users'].sudo().search([('character_id', '=', character_id)], limit=1) if not user: user = request.env['res.users'].sudo().create({ 'name': character_name, 'login': email, 'character_id': character_id, }) return {'status': 'success'}
-
Extend the Odoo User Model: models/eve_user.py:
from odoo import models, fields class ResUsers(models.Model): _inherit = 'res.users' character_id = fields.Char('Character ID') character_name = fields.Char('Character Name')
-
Initialize the Module: init.py:
from . import controllers from . import models
-
Install and Test the Odoo Module:
- Place the module in the Odoo addons directory and install it through the Odoo interface.
- Ensure that the endpoint
/eve/auth
is available and can handle incoming user data.
Step 3: Update the Flask Server to Communicate with Odoo
- Modify
callback
Function inapp.py
: app.py:from flask import Flask, render_template, redirect, request import requests from utils.oauth import get_access_token, fetch_user_data from dotenv import load_dotenv import os load_dotenv() app = Flask(__name__) CLIENT_ID = os.getenv('EVE_CLIENT_ID') CLIENT_SECRET = os.getenv('EVE_CLIENT_SECRET') REDIRECT_URI = os.getenv('EVE_REDIRECT_URI') SCOPE = 'esi-characters.read_corporation_roles.v1 esi-mail.send_mail.v1' @app.route('/') def index(): return render_template('login.html') @app.route('/login') def login(): return redirect(f'https://login.eveonline.com/v2/oauth/authorize/?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}') @app.route('/callback') def callback(): code = request.args.get('code') access_token = get_access_token(code) user_data = fetch_user_data(access_token) # Send user data to Odoo odoo_url = 'http://your-odoo-instance.com/eve/auth' response = requests.post(odoo_url, json=user_data) return render_template('success.html', user_data=user_data) if __name__ == '__main__': app.run(debug=True)
Summary
- Set Up Flask Server: Ensure all files are in place, install dependencies, and run the server.
- Create Custom Odoo Module: Set up the module to handle incoming user data.
- Update Flask Server: Modify the
callback
function to send user data to Odoo.
This will integrate the user authentication system with Odoo. Let me know if you need any more help or if youβre ready to proceed! π