Sara
Sara

Reputation: 623

Authentication using Google Service Account in a flask app and deploying on Google App Engine

Below are my requirements.

What I have done.

cred = credentials.Certificate('key.json') 
default_app = initialize_app(cred) 
db = firestore.client()

user_ref = db.collection_group('Users')

@app.route('/', methods=['GET']) 
def home():
return "<h1>Welcome to my first app</h1>"

@app.route('/users', methods=['GET'])
def getUsers():
    try:
        result = [user.to_dict() for user in user_ref .stream()]
        return jsonify(result), 200
    except Exception as e:
        result = { "message:"failed"}
        return jsonify(result), 500

I have tested this locally and also on deployed on Google App Engine.

In both the cases, key.json was in the same directory as the code. I have verified that if this key.json is modified to store wrong data, then /users endpoint won't work and gives me a 500 error.

So far so good. I want to know if this is even the right approach.

Upvotes: 0

Views: 1197

Answers (2)

Sara
Sara

Reputation: 623

I have found that we can use Google Cloud Endpoints for API management. Works as a charm.

Upvotes: 0

Rafael Lemos
Rafael Lemos

Reputation: 5829

As mentioned by @Gaefan and @DishantMakwana, as well as in this documentation:

An API key only identifies the application and doesn't require user authentication. It is sufficient for accessing public data.

So in order to authenticate/authorize your users you should reconsider your strategy. I would recommend you to follow the instructions in the Authenticating as an end user Documentation.

Upvotes: 1

Related Questions