jeudi 2 mars 2017

redirectng to external URL not working at times

Below is the Flask application(version 0.7) snippet which is used to view reports. I'm new to Python and Flask and I'm trying to authenticate user request using Single sign on(sso) using before_request decorator. Its working as expected when user trying to browse/ launch http://host_name:8084/ its navigating to External domain SSO application(java + apache) url to authenticate.

import os
from flask import Flask
import flask
import urllib

app = Flask(__name__)

# Registers url to run before each request
@app.before_request
def before_request():
    return _redirectSSO(flask.request)


def _redirectSSO(reuested_url):
    # External Domain SSO URL to authenticate user
    url = 'https://ssologon/ssologinconfirm.html?target={0}'.format(urllib.quote_plus(reuested_url))

    return flask.redirect(url)

@app.route('/')
def hello():
    return "Hello World"


@app.route('/documents/<reportFileName>')
def view_document():
    data = dist.retrive_data() # retrive pdf/ ppt data object
    response = flask.make_response(data)
    ext  = reportFileName.split('.')[-1]  
    response.headers['Content-Type'] = 'application/{0}'.format(ext)
    response.headers['Content-Disposition'] = 'inline; filename={0}'.format(reportFileName)

    returns response

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port) # http://host_name:8084/

when user trying to open/clicking the url directly(http://host_name:8084/documents/report file name_2017.pdf)Its working as expected by navigating to sso and bouncing back to original Url but its not working at times. url clicks are taking to web page but url string not responding/ not navigating to sso page in browser.

We are not able to reproduce this issue because its failing once in a while with 500 error.

Its very strange to see same url string for failure(url not navigating to sso)/ success of the url(navigating to sso) cases. Am i missing any header tags hear or missing any url related formats or is there any known issue with flask to navigate to external domain urls. Please suggest me how can i make my application work with out any fail or missing any response code please help to navigate original--> sso url --> original url

thanks in advance




Aucun commentaire:

Enregistrer un commentaire