when we add a redirect uri in apple developer portal a trailing slash is added by default sometimes so I added that in my code as well and it worked!
I think we just have to keep it same everywhere.