Zerodha Login redirect issue

vishalmote
vishalmote edited April 26 in General
As we are developing an application using Angular technology, and Angular routes/urls work after #.

Our redirect url is as below :-

https://www.fando.in/#/zerodhaRedirect


but kite redirection is altering it as below :-


https://www.fando.in/?action=login&type=login&status=success&request_token=abcdSassEE32DFssa#/zerodhaRedirect


Expected Redirect should be :-


https://www.fando.in/#/zerodhaRedirect?action=login&type=login&status=success&request_token=abcdSassEE32DFssa
  • SRIJAN
    SRIJAN edited April 26
    But you still have the request token which you need in the url. Where's the problem??
  • vishalmote
    all the code which process request_token is inside zerodhaRedirect controller. not in base controller / . so this request_token will not be able to process inside base controller. base controller is primarily for just redirecting to appropriate route or default route.
  • vishalmote
    redirection should be on given url, right?, else if you are going to actually redirect to base_url then there is no need to ask for redirect_url separately in app configuration. Don't you think so?
  • Vivek
    Vivek edited April 26
    In Kite redirect flow we have to append some query params to the final redirect URL like `status` and `request_token`. So here the problem is that angular uses hash fragment to do the frontend routing but as per URL standard formats the hash fragment is always the last part of the URL after query param since anything which comes after hash fragment is considered part of the hash fragment.

    For example check this

    Actual redirect below. You can see that `hash: "#/zerodhaRedirect"` which is parsed correctly.
    new URL("https://www.fando.in/?action=login&type=login&status=success&request_token=abcdSassEE32DFssa#/zerodhaRedirect")

    hash: "#/zerodhaRedirect"
    host: "www.fando.in"
    hostname: "www.fando.in"
    href: "https://www.fando.in/?action=login&type=login&status=success&request_token=abcdSassEE32DFssa#/zerodhaRedirect"
    origin: "https://www.fando.in"
    password: ""
    pathname: "/"
    port: ""
    protocol: "https:"
    search: "?action=login&type=login&status=success&request_token=abcdSassEE32DFssa"

    Redirect you are expecting. You can see that `hash: "#/zerodhaRedirect?action=login&type=login&status=success&request_token=abcdSassEE32DFssa"` which is wrongly parsed.
    new URL("https://www.fando.in/#/zerodhaRedirect?action=login&type=login&status=success&request_token=abcdSassEE32DFssa")

    hash: "#/zerodhaRedirect?action=login&type=login&status=success&request_token=abcdSassEE32DFssa"
    host: "www.fando.in"
    hostname: "www.fando.in"
    href: "https://www.fando.in/#/zerodhaRedirect?action=login&type=login&status=success&request_token=abcdSassEE32DFssa"
    origin: "https://www.fando.in"
    password: ""
    pathname: "/"
    port: ""
    protocol: "https:"
    search: ""
    So what Kite redirects to is fine, its just that Angular is not handling both query params and hash fragment in the URL properly. Easy solution is to handle the redirect in your backend only or switch Angular to `PathLocationStrategy` instead of `HashLocationStrategy`.
  • vishalmote
    Hi thanks for reply, Yes I can handle redirection at backend and just again read the documentation that you have redirect_params option in login api to get back extra unique identification for user session at my end. This resolves my problem. thank you.

  • vishalmote
    vishalmote edited April 27
    Additional point :- `PathLocationStrategy` has demerits, it doesn't load a page on page refresh[ctrl+r or f5] so we have to switch it to `HashLocationStrategy`. still I believe kite redirect API is not correct or we can say not compatible with latest frameworks in market like Angular and ReactJs. there should be extra additional configuration that application is in latest frontend frameworks or traditional code which is in plain javascript & html. on that basis # route should adjusted before redirecting.
  • Vivek
    I am not sure how it works in Angular but In Vue and React atleast you can refresh the page with location history on so there must be some workaround in Angular.

    > still I believe kite redirect API is not correct or we can say not compatible with latest frameworks in market like Angular and ReactJs

    As I said we are just following the URL standard, if we don't then it will break for many others so if you are using some tech which doesn't honor the url standards then you need to make a workaround.
  • vishalmote
    vishalmote edited April 27
    @Vivek, Thanks for revert, need to dig deeper down regarding angular.
  • vishalmote
    Just Updating for somebody else reference. combination of PathLocationStrategy and redirection to index.html using .htaccess resolve issue of non # url page refresh issue. and and without # kite redirection works fine.

    https://www.tektutorialshub.com/angular/the-requested-url-was-not-found-on-this-server-error-in-angular/
Sign In or Register to comment.