jwt - Django - How to implement authentication service in microservices architecture -


basically, have several independent services. want build service authentication. when client token authentication service. client use further request others services. client need attach token in header of request. services receiving token need verify token sending authentication server. requests clients make protected routes need verified authentication service. thing not know best place put code automatically sends token authentication service , receive result. here tried far: implemented middleware that:

class verifytokenmiddleware(object):  def process_request(self, request):     if not request.meta.get('http_authorization'):         return httpresponse(status=404)     auth_header = request.meta.get('http_authorization')     token = auth_header[4:]     response = requests.post(auth_url, {"token": token})     if response.status_code == 400:         return httpresponse(status=403)     return none 

however, problem of solution every requests services(not auth service) have pass through middleware. therefore, client cannot access unprotected routes before. extremely appreciated. :d

i used django restframework jwt https://github.com/getblimp/django-rest-framework-jwt.

it have many way desiged microservice, can write file restfull method

class restfulclient:    @classmethod    def get(cls, url, loggers, headers):        return is_success, status_code, data     @classmethod    def post(cls, url, headers, loggers, params={}):        return is_success, status_code, status_message, data     @classmethod    def put(cls, url, headers, loggers, params={}):        return is_success, status_code, status_message, data     @classmethod    def delete(cls, url, headers, loggers, params={}):        return is_success, status_code, status_message 

any question?


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -