librelist archives

« back to archive

HTTPS Redirect

HTTPS Redirect

From:
Daniel Nümm
Date:
2014-12-01 @ 13:34
  Hi,

i have a question about redirecting a path like in the example code below.
If I call "/test_redirect/“ over HTTPS the redirect ends on HTTP. Is this 
the correct behavior? And if, how can I force Redirection with the current
Protocol?

Thx. Daniel 


    @app.route('/test_redirect/')
    def test_redirect():
        return redirect('/target/')

    @app.route('/target/')
    def target():
        return ‘hello'


try it online

    https://fb-gallery-master.apps.eightbrain.org/test_redirect

Re: [flask] HTTPS Redirect

From:
Scott Werner
Date:
2014-12-01 @ 13:51
You want to use:
return redirect(url_for(‘target’, _scheme="https"))

See https://github.com/mattupstate/flask-security/issues/338

Thanks,
Scott Werner

From: flask@librelist.com [mailto:flask@librelist.com] On Behalf Of Daniel Nümm
Sent: Monday, December 01, 2014 8:35 AM
To: flask@librelist.com
Subject: [flask] HTTPS Redirect

Hi,

i have a question about redirecting a path like in the example code below.
If I call "/test_redirect/“ over HTTPS the redirect ends on HTTP. Is this 
the correct behavior? And if, how can I force Redirection with the current
Protocol?

Thx. Daniel


    @app.route('/test_redirect/')
    def test_redirect():
        return redirect('/target/')

    @app.route('/target/')
    def target():
        return ‘hello'


try it online

    https://fb-gallery-master.apps.eightbrain.org/test_redirect

Re: [flask] HTTPS Redirect

From:
Daniel Nümm
Date:
2014-12-01 @ 14:40
  Not realy, i am looking for a solution with domain and http/https 
independent support. 


The project is a Facebook tab app and FB require HTTPS but mobile users 
are on a different domain because FB doesn't support this Tabs on Mobile 
Devices.


    https://ssl-domain.tld/test -> https://ssl-domain.tld/done
    http://domain.tld/test -> http://domain.tld/done


so i need a solution with a path redirect and the current scheme.





> On Dec 1, 2014, at 2:51 PM, Scott Werner <scott.werner@autodesk.com> wrote:
> 
> 
> You want to use:
> 
> 
> return redirect(url_for(‘target’, _scheme="https"))
> 
> 
>  
> 
> 
> Seehttps://github.com/mattupstate/flask-security/issues/338
> 
> 
> 
>  
> 
> 
> Thanks,
> 
> 
> Scott Werner
> 
> 
> 
>  
> 
> 
> From:flask@librelist.com [mailto:flask@librelist.com]On Behalf Of Daniel Nümm
> Sent:Monday, December 01, 2014 8:35 AM
> To:flask@librelist.com
> Subject:[flask] HTTPS Redirect
> 
> 
> 
> 
> 
>  
> 
> Hi,
> 
> i have a question about redirecting a path like in the example code 
below. If I call "/test_redirect/“ over HTTPS the redirect ends on HTTP. 
Is this the correct behavior? And if, how can I force Redirection with the
current Protocol?
> 
> Thx. Daniel 
> 
> 
>     @app.route('/test_redirect/')
>     def test_redirect():
>         return redirect('/target/')
> 
>     @app.route('/target/')
>     def target():
>         return ‘hello'
> 
> 
> try it online
> 
>     https://fb-gallery-master.apps.eightbrain.org/test_redirect
> 
> 
> 

Re: [flask] HTTPS Redirect

From:
Samir Naik
Date:
2014-12-01 @ 19:48
This should work:

return redirect (request.host_url + "/done")

On Mon, Dec 1, 2014 at 6:40 AM, Daniel Nümm <daniel.nuemm@eightbrain.org>
wrote:

>   Not realy, i am looking for a solution with domain and http/https
> independent support.
>
> The project is a Facebook tab app and FB require HTTPS but mobile users
> are on a different domain because FB doesn't support this Tabs on Mobile
> Devices.
>
>     https://ssl-domain.tld/test -> https://ssl-domain.tld/done
>     http://domain.tld/test -> http://domain.tld/done
>
> so i need a solution with a path redirect and the current scheme.
>
>
>  On Dec 1, 2014, at 2:51 PM, Scott Werner <scott.werner@autodesk.com>
> wrote:
>
> You want to use:
>
> return redirect(url_for(‘target’, _scheme="https"))
>
>
> Seehttps://github.com/mattupstate/flask-security/issues/338
>
>
>  Thanks,
>
> Scott Werner
>
>
>  *From:*flask@librelist.com [mailto:flask@librelist.com]*On Behalf Of *Daniel
> Nümm
> *Sent:*Monday, December 01, 2014 8:35 AM
> *To:*flask@librelist.com
> *Subject:*[flask] HTTPS Redirect
>
>
> Hi,
>
> i have a question about redirecting a path like in the example code below.
> If I call "/test_redirect/“ over HTTPS the redirect ends on HTTP. Is this
> the correct behavior? And if, how can I force Redirection with the current
> Protocol?
>
> Thx. Daniel
>
>
>     @app.route('/test_redirect/')
>     def test_redirect():
>         return redirect('/target/')
>
>     @app.route('/target/')
>     def target():
>         return ‘hello'
>
>
> try it online
>
>     https://fb-gallery-master.apps.eightbrain.org/test_redirect
>
>

Re: [flask] HTTPS Redirect

From:
Daniel Nümm
Date:
2014-12-01 @ 21:51
Thank you for putting me in the right direction. Now I have something like this.


@app.before_request
def before_request():
    app.config['SERVER_NAME'] = request.host


@app.route('/test_redirect/')
def test_redirect():
    return redirect(url_for('target', _external=True, _scheme=request.scheme))

@app.route('/target/')
def target():
    return 'hello'

Re: [flask] HTTPS Redirect

From:
Minh Ngo
Date:
2014-12-02 @ 09:17
Hi,

I have a relatively the same problem, but my server is behind nginx that
redirects requests from my domain to the local server.

The last solution, proposed by Daniel, will not work for me because in my
case request.host == HOST + ":" + PORT, where HOST == 127.0.0.1. And when
I'm doing, for example, Facebook OAuth the external domain is needed to be
redirected correctly from Facebook.

At the moment I'm doing like that:

return facebook.authorize(callback=PROTOCOL + "://" + HOST +
"/auth/authorized?next=%2Fblog"), that is not so nice

Maybe anybody know a better solution?

Regards,

Minh



On 1 December 2014 at 23:51, Daniel Nümm <daniel.nuemm@eightbrain.org>
wrote:

>  Thank you for putting me in the right direction. Now I have something
> like this.
>
> @app.before_request
> def before_request():
>     app.config['SERVER_NAME'] = request.host
>
> @app.route('/test_redirect/')
> def test_redirect():
>     return redirect(url_for('target', _external=True,
> _scheme=request.scheme))
>
> @app.route('/target/')
> def target():
>     return 'hello'
>

Re: [flask] HTTPS Redirect

From:
Daniel Nümm
Date:
2014-12-02 @ 10:40
  Hey Minh,


    proxy_set_header    Host            $host;



try this in your nginx config below proxy_pass.






> On Dec 2, 2014, at 10:17 AM, Minh Ngo <nlminhtl@gmail.com> wrote:
> 
> 
> Hi,
> 
> 
> I have a relatively the same problem, but my server is behind nginx that
redirects requests from my domain to the local server.
> 
> The last solution, proposed by Daniel, will not work for me because in 
my case request.host == HOST + ":" + PORT, where HOST == 127.0.0.1. And 
when I'm doing, for example, Facebook OAuth the external domain is needed 
to be redirected correctly from Facebook.
> 
> 
> At the moment I'm doing like that:
> 
> return facebook.authorize(callback=PROTOCOL + "://" + HOST + 
"/auth/authorized?next=%2Fblog"), that is not so nice
> 
> 
> Maybe anybody know a better solution?
> 
> 
> Regards,
> 
> Minh
> 
> 
> 
> On 1 December 2014 at 23:51, Daniel Nümm <daniel.nuemm@eightbrain.org
>>wro te:
>> 
>> Thank you for putting me in the right direction. Now I have something 
like this.
>> 
>> 
>> @app.before_request
>> def before_request():
>>     app.config['SERVER_NAME'] = request.host
>> 
>> 
>> @app.route('/test_redirect/')
>> def test_redirect():
>>     return redirect(url_for('target', _external=True, _scheme=request.scheme))
>> 
>> @app.route('/target/')
>> def target():
>>     return 'hello'
>> 
>> 
>> 
> 
> 
> 
> 
> 
> 
> 
> 

Re: [flask] HTTPS Redirect

From:
John Goodyear
Date:
2014-12-02 @ 11:16
Another nginx way to solve this is to just redirect all HTTP to HTTPS:

server {
    listen         80;
    return 301 https://$host$request_uri;
}



On Tue, Dec 2, 2014 at 10:40 AM, Daniel Nümm <daniel.nuemm@eightbrain.org>
wrote:

>  Hey Minh,
>
>     proxy_set_header    Host            $host;
>
> try this in your nginx config below proxy_pass.
>
>
>  On Dec 2, 2014, at 10:17 AM, Minh Ngo <nlminhtl@gmail.com> wrote:
>
>   Hi,
>
> I have a relatively the same problem, but my server is behind nginx that
> redirects requests from my domain to the local server.
>
> The last solution, proposed by Daniel, will not work for me because in my
> case request.host == HOST + ":" + PORT, where HOST == 127.0.0.1. And when
> I'm doing, for example, Facebook OAuth the external domain is needed to be
> redirected correctly from Facebook.
>
> At the moment I'm doing like that:
>
> return facebook.authorize(callback=PROTOCOL + "://" + HOST +
> "/auth/authorized?next=%2Fblog"), that is not so nice
>
> Maybe anybody know a better solution?
>
>  Regards,
>
> Minh
>
>
>
> On 1 December 2014 at 23:51, Daniel Nümm <daniel.nuemm@eightbrain.org>wro
> te:
>
>>  Thank you for putting me in the right direction. Now I have something
>> like this.
>>
>> @app.before_request
>> def before_request():
>>     app.config['SERVER_NAME'] = request.host
>>
>>  @app.route('/test_redirect/')
>> def test_redirect():
>>     return redirect(url_for('target', _external=True,
>> _scheme=request.scheme))
>>
>> @app.route('/target/')
>> def target():
>>     return 'hello'
>>
>
>

Re: [flask] HTTPS Redirect

From:
Jonathan Grahl
Date:
2014-12-01 @ 13:49
The easiest way is to use url_for to create the URL:

return redirect(url_for(’target’, scheme=“https”))
Preferably you’d want HTTPS automatically redirected by the web server 
(e.g nginx).
-- 
Jonathan Grahl
Sent with Airmail

On 1 Dec 2014 at 14:38:54, Daniel Nümm (daniel.nuemm@eightbrain.org) wrote:

Hi,

i have a question about redirecting a path like in the example code below.
If I call "/test_redirect/“ over HTTPS the redirect ends on HTTP. Is this 
the correct behavior? And if, how can I force Redirection with the current
Protocol?

Thx. Daniel 


    @app.route('/test_redirect/')
    def test_redirect():
        return redirect('/target/')

    @app.route('/target/')
    def target():
        return ‘hello'


try it online

    https://fb-gallery-master.apps.eightbrain.org/test_redirect