Python 否';访问控制允许原点';请求的资源上存在标头
当这个API(在托管服务器上)在前端调用时,它将重定向到GoogleOAuth,以便在出现此错误时进行Google登录 CORS策略已阻止从源“”在“”处(从“”重定向)获取的访问:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许源”标头。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源 我使用的环境是: 后端-Python 前端-reactjs webservicer-WEBHOSTPYTHON 在这里,我为goggle oAuthentication添加了服务器端代码Python 否';访问控制允许原点';请求的资源上存在标头,python,reactjs,google-api,youtube-data-api,flask-cors,Python,Reactjs,Google Api,Youtube Data Api,Flask Cors,当这个API(在托管服务器上)在前端调用时,它将重定向到GoogleOAuth,以便在出现此错误时进行Google登录 CORS策略已阻止从源“”在“”处(从“”重定向)获取的访问:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在“访问控制允许源”标头。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源 我使用的环境是: 后端-Python 前端-reactjs webservicer-WEBHOSTPYTHON 在这里,我为goggle oAu
@app.route('/oauth2callback',methods=['GET', 'POST'])
@cross_origin(origins='*',allow_headers=['Access-Control-Allow-
Origin'])
def oauth2callback():
# Specify the state when creating the flow in the callback so that
it can
# verify the authorization server response.
state = flask.session['state']
flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
CLIENT_SECRETS_FILE, scopes=SCOPES, state=state)
flow.redirect_uri = flask.url_for('oauth2callback',
_external=True)
# Use the authorization server's response to fetch the OAuth 2.0
tokens.
authorization_response = flask.request.url
#authorization_response = flask.request.headers['Access-Control-
Allow-Origin'] = '*'
authorization_response = flask.Response.headers.set['Access-
Control-Allow-Origin'] = '*'
authorization_response = authorization_response.replace('http',
'https')
client_secret = 'lDXXXXXXXXXXXXXXXXZoK'
flow.fetch_token(client_secret=client_secret,
authorization_response=authorization_response)
# Store the credentials in the session.
# ACTION ITEM for developers:
# Store user's access and refresh tokens in your data store if
# incorporating this code into your real app.
credentials = flow.credentials
flask.session['credentials'] = {
'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes
}
data1=flask.redirect(flask.url_for('index'))
data1.headers['Access-Control-Allow-Origin'] = '*'
return data1
获取错误时前端屏幕短