python - Flask CORS - no Access-control-allow-origin header present on a redirect() -


i implementing oauth twitter user-sign in (flask api , angular)

i keep getting following error when click sign in twitter button , pop window opens:

xmlhttprequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=r-eufwaaaaaagjsmaaabtp8vcie. no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. 

i using python-cors packages handle cors, , have instagram sign in working correctly. believe has response being redirect have not been able correct problem.

my flask code looks this:

app = flask(__name__, static_url_path='', static_folder=client_path) cors = cors(app, allow_headers='content-type', cors_send_wildcard=true) app.config.from_object('config')  @app.route('/auth/twitter', methods=['post','options']) @cross_origin(origins='*', send_wildcard=true) #@crossdomain(origin='') def twitter():     request_token_url = 'https://api.twitter.com/oauth/request_token'     access_token_url = 'https://api.twitter.com/oauth/access_token'     authenticate_url = 'https://api.twitter.com/oauth/authenticate'      # print request.headers      if request.args.get('oauth_token') , request.args.get('oauth_verifier'):         -- omitted brevity --     else:         oauth = oauth1(app.config['twitter_consumer_key'],                        client_secret=app.config['twitter_consumer_secret'],                        callback_uri=app.config['twitter_callback_url'])         r = requests.post(request_token_url, auth=oauth)         oauth_token = dict(parse_qsl(r.text))         qs = urlencode(dict(oauth_token=oauth_token['oauth_token']))         return redirect(authenticate_url + '?' + qs) 

the problem not yours. client-side application sending requests twitter, isn't need support cors, twitter. twitter api not support cors, means cannot talk directly browser.

a common practice avoid problem have client-side app send authentication requests server of own (such same flask application have), , in turn server connects twitter api. since server side isn't bound cors requirements there no problem.

in case want ideas, have written blog article on doing type of authentication flow facebook , twitter: http://blog.miguelgrinberg.com/post/oauth-authentication-with-flask


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -