OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I make all requests to my firebase flask server be authenticated

  • Thread starter Thread starter Possible Panda
  • Start date Start date
P

Possible Panda

Guest
I'm trying to make some sort of authentication system for my server for a game I'm working on. I want to make it so I can make it so certain routes require you to be authenticated to interact with them. Anyone have any ideas? Here's my code

server.py

Code:
from flask import Flask, redirect, request, jsonify
import time
import json
import jwt
import firebase
from functools import wraps

app = Flask(__name__)

# All entries
@app.route("/entries")
def entries():
    return firebase.get_entries()

# Get specific entry
@app.route("/entries/<string:id>")
def entry(id):
    return firebase.get_entry(id)

# Get specific entry's property
@app.route("/entries/<string:id>/<string:property>")
def entry_property(id, property):
    return firebase.get_entry(id)[property]

# Create entry
@app.route("/create_entry/<string:id>")
def create_entry(id):
    try:
        name = request.args.get("name")
        description = request.args.get("description")
        
        entry = {
            "name": name,
            "description": description,
        }
        
        e = firebase.create_entry(id, entry)

        if e:
            return str(e)
        
        return f"Created entry with the id of {id}"
    except Exception as e:
        return e

# Remove "/" from end
@app.before_request
def trailing():
    from flask import redirect, request

    rp = request.path 
    if rp != '/' and rp.endswith('/'):
        return "Don't use trailing backslashes. Example: /entries, not /entries/", 404


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000, debug=True)

I have tried using AI, and it got me extremely annoyed so I probably won't do that again...

Any help is appreciated :)
<p>I'm trying to make some sort of authentication system for my server for a game I'm working on. I want to make it so I can make it so certain routes require you to be authenticated to interact with them. Anyone have any ideas? Here's my code</p>
<p><code>server.py</code></p>
<pre class="lang-py prettyprint-override"><code>from flask import Flask, redirect, request, jsonify
import time
import json
import jwt
import firebase
from functools import wraps

app = Flask(__name__)

# All entries
@app.route("/entries")
def entries():
return firebase.get_entries()

# Get specific entry
@app.route("/entries/<string:id>")
def entry(id):
return firebase.get_entry(id)

# Get specific entry's property
@app.route("/entries/<string:id>/<string:property>")
def entry_property(id, property):
return firebase.get_entry(id)[property]

# Create entry
@app.route("/create_entry/<string:id>")
def create_entry(id):
try:
name = request.args.get("name")
description = request.args.get("description")

entry = {
"name": name,
"description": description,
}

e = firebase.create_entry(id, entry)

if e:
return str(e)

return f"Created entry with the id of {id}"
except Exception as e:
return e

# Remove "/" from end
@app.before_request
def trailing():
from flask import redirect, request

rp = request.path
if rp != '/' and rp.endswith('/'):
return "Don't use trailing backslashes. Example: /entries, not /entries/", 404


if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
</code></pre>
<p>I have tried using AI, and it got me extremely annoyed so I probably won't do that again...</p>
<p>Any help is appreciated :)</p>
 

Latest posts

Top