Google signin API using oauth Post Method in python flask server

I got question about implementing google login. I was able to implement Google Login button on my react app using an open source library called react-google-login. I was able to set up the backend server using python flask. I host my api method on the api on Heroku: http://arrangement-server.herokuapp.com/login. And my react app runs successfully locally, and I am able to use login-in button. But, my issue is that my server displays the following error:

Method not Allowed.

Is this because it is post method?

Why is it my Server shows me that that method is not allowed?

enter image description here

Even though on the client side it runs fine, and I am able to see user profile and user information.

Here's the code to my backend server, you can find it at Github:

@app.route("/login", methods=['POST'])
def login():
    data = request.json
    session['access_token'] = data['access_token'], ''
    return jsonify({'message':'You are logged in.'})  
728x90

3 Answers Google signin API using oauth Post Method in python flask server

I think this part

@app.route("/")
def home_page():
    access_token = session.get('access_token')
    if access_token is None:
        return redirect(url_for('login'))

Always force user to visit login page with GET method. Unfortunately you don't have method and route defined to handle this GET method.

4 months ago

Your "login" endpoint will accept only "POST" HTTP requests. Because of this line:

@app.route("/login", methods=['POST'])

When you try to open your page in a browser - the browser will send the "GET" HTTP request to that URL.

That is why you are getting "Method Not Allowed" error. Take a look at my answer on upwork for more details.

4 months ago

Your heroku server is only a backend server. And the route "/login" accepts only POST request. So you can't send the GET request to this route on web browser. If you want to look at the response with this route, you can send the POST request by using POSTMAN.

3 months ago