Hi Everyone,
I am creating a custom plugin in python for my own authentication process i have some confusions if anyone can help me so i will be very thankfull.
Currently i take the demo plugin from tyk documentation for learning and i have 2 questions here:
First one is in middleware.py file
from tyk.decorators import *
from gateway import TykGateway as tyk
@Hook
def MyAuthMiddleware(request, session, metadata, spec):
auth_header = request.get_header(‘Authorization’)
if auth_header ==auth_header:
session.rate = 1000.0
session.per = 1.0
metadata[“token”] = “47a0c79c427728b3df4af62b9228c8ae”
return request, session, metadata
Everytime when condition will be true then request will parse forword and target url hit i mean in success case every time we will return session,request and metadata???
second one is more important for me that in case of condition false i want to return back the response from here like {code:401 ,messege:" Unauthorized error"} how can i achieved this ??
Thankyou in Advance