-
Notifications
You must be signed in to change notification settings - Fork 2
Authenticate Public API request
Bishal Pun edited this page Jun 3, 2018
·
2 revisions
This section shows the steps to authenticate the public API request sent by clients with client id and api access secret key.
Note
This tutorial is for the backend developer who are creating REST API for a client.
- Import the API Validator.
from odoo.addons.auth_api_hmac.auth.validator import APIValidator- Call the authenticate_api method for authenticating the API request.
# -*- coding: utf-8 -*-
import werkzeug
import json
import logging
from odoo import http
from odoo.addons import oauth_provider
from odoo.addons.web.controllers.main import ensure_db
from odoo.addons.auth_api_hmac.auth.validator import APIValidator
_logger = logging.getLogger(__name__)
class OAuth2ProviderController(
http.Controller):
@http.route(
'/oauth2/get_tags', type='http', auth='none', methods=['GET'])
def test(self, *args, **kwargs):
""" Returns the public key of the requested client """
ensure_db()
client = APIValidator.authenticate_api(http.request.httprequest)
if not client:
return self._json_response(
data={'error': 'invalid_or_expired_token'}, status=401)
data = {"client_id": client.identifier}
return self._json_response(data=data)APIOdooValidator.authenticate_api(http.request.httprequest, *args, **kwargs)