Skip to content

Using /authorize with SPA

Hi, i have a question (or issue) about using /authorize endpoint with SPA. Now, /authorize sends response with status 302 and put redirect_url to Location header. But FE can't handle 302 response.

    # File: oauth_authorization_code_grant.rb

    # /authorize
    route(:authorize) do |r|
      # ...some code here...

      r.post do
        params, mode = transaction do
          before_authorize
          do_authorize
        end

        authorize_response(params, mode)
      end
    end

method do_authorize build params and mode -> [{"code"=>"some-token"}, "query"]

    # File: oauth_authorization_code_grant.rb

    def authorize_response(params, mode)
      redirect_url = URI.parse(redirect_uri)
      case mode
      when "query"
        params = params.map { |k, v| "#{k}=#{v}" }
        params << redirect_url.query if redirect_url.query
        redirect_url.query = params.join("&")
        redirect(redirect_url.to_s)
      # ...some code here for "form_post" and "none"...
      end
    end

Here we have logic for "query" mode and it builds redirect url and call redirect to url After that it returns 302 with Location If i try send request /authorize with content-type "application/json" it returns only 200 OK with empty body. I expect that body will contain payload with redirect url.

Could you please give me some advice, how i can resolve it?

Edited by Dmitriy But