Question: Google App Engine Flask Error in 'Access-Control-Allow-Origin' CORPS settings

Question

Google App Engine Flask Error in 'Access-Control-Allow-Origin' CORPS settings

Answers 0
Added at 2016-12-26 17:12
Tags
Question

I am using Google App Engine and flask to get the authentication from the Facebook I have created the FB Application and it connects fine

I am using the following libraries

  • flask-cors==2.1.2
  • flask-restful==0.3.5

I am setting CORS settings as follows

cors = CORS(app, resources={r"/api/v1/*": {"origins": "*"}})

I am getting the following error

 XMLHttpRequest cannot load https://www.facebook.com/dialog/oauth?response_type=code&client_id=40400553…alhost%3A8080%2Fapi%2Fv1%2Fusers%2Ffacebook2%2F&scope=email&_external=True. Redirect from 'https://www.facebook.com/dialog/oauth?response_type=code&client_id=40400553…alhost%3A8080%2Fapi%2Fv1%2Fusers%2Ffacebook2%2F&scope=email&_external=True' to 'https://www.facebook.com/login.php?skip_api_login=1&api_key=404005532980775…_&display=page&locale=en_GB&logger_id=c25bd044-3438-4a9b-b9ef-3f1701bf1d1c' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Request Handler

SECRET_KEY = 'development key'
DEBUG = True
FACEBOOK_APP_ID = '40400553-----'
FACEBOOK_APP_SECRET = 'bc04c3c33f-----'

facebook_config = dict(
  access_token_url='/oauth/access_token',
  authorize_url='/oauth/authorize',
  base_url='https://graph.facebook.com/',
  consumer_key=FACEBOOK_APP_ID,
  consumer_secret=FACEBOOK_APP_SECRET,
  request_token_params={'scope': 'email'},
)

            def create_oauth_app(service_config, name):
              upper_name = name.upper()
              app.config[upper_name] = service_config
              service_oauth = oauth.OAuth()
              service_app = service_oauth.remote_app(name, app_key=upper_name)
              service_oauth.init_app(app)
              return service_app


          def signin_fb_oauth(oauthapp, scheme=None):
              try:
                flask.session.pop('oauth_token', None)
                save_request_params()
                print '****************************'
                print 'signin oauth'
                print '*******************************'
                #call_back_url_appengine = 'http://localhost:3000/api/v1/users/facebook2/'
                call_back_url_flask= 'http://localhost:8080/api/v1/users/facebook2/'
                fb_auth = oauthapp.authorize(
                  callback=call_back_url_flask,
                  _external=True
                )

                return  fb_auth
                  except oauth.OAuthException:
                  flask.flash(
                  'Something went wrong with sign in. Please try again.',
                  category='danger',
                )
                print '*******************************************'
                print 'Error in AuthenticationError'
                print '*******************************************'
                return flask.redirect(flask.url_for('signin',     next=util.get_next_url()))

This application has a Angualr2 front end and Flask Google App Engine Backend

What could possibly go wrong here ?

enter image description here

Answers
Source Show
◀ Wstecz