Skip to content

Commit 7a0928f

Browse files
committed
Allow to use Firebase Auth in debug mode.
1 parent e746bf0 commit 7a0928f

File tree

5 files changed

+21
-32
lines changed

5 files changed

+21
-32
lines changed

flask_firebase/__init__.py

+11-22
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def __init__(self, app=None):
6161
def init_app(self, app):
6262
app.extensions['firebase_auth'] = self
6363
self.debug = app.debug
64-
if self.debug:
64+
self.api_key = app.config.get('FIREBASE_API_KEY')
65+
if self.api_key is None:
6566
return
66-
self.api_key = app.config['FIREBASE_API_KEY']
6767
self.project_id = app.config['FIREBASE_PROJECT_ID']
6868
self.server_name = app.config['SERVER_NAME']
6969
provider_ids = []
@@ -86,31 +86,20 @@ def unloader(self, callback):
8686
return callback
8787

8888
def url_for(self, endpoint, **values):
89-
full_endpoint = 'firebase_auth.{}'.format(endpoint)
90-
if self.debug:
91-
return url_for(full_endpoint, **values)
92-
else:
93-
return url_for(
94-
full_endpoint,
95-
_external=True,
96-
_scheme='https',
97-
**values)
89+
return url_for(
90+
'firebase_auth.{}'.format(endpoint),
91+
_external=True,
92+
_scheme='http' if self.debug else 'https',
93+
**values)
9894

9995
def widget(self):
10096
next_ = self.verify_redirection()
101-
if self.debug:
102-
if request.method == 'POST':
103-
self.development_load_callback(request.form['email'])
104-
return redirect(next_)
105-
else:
106-
return render_template('firebase_auth/development_widget.html')
107-
else:
108-
return render_template(
109-
'firebase_auth/production_widget.html',
110-
firebase_auth=self)
97+
if self.debug and request.method == 'POST':
98+
self.development_load_callback(request.form['email'])
99+
return redirect(next_)
100+
return render_template('firebase_auth/widget.html', firebase_auth=self)
111101

112102
def sign_in(self):
113-
assert not self.debug
114103
header = jwt.get_unverified_header(request.data)
115104
with self.lock:
116105
self.refresh_keys()

flask_firebase/templates/firebase_auth/development_widget.html

-9
This file was deleted.

flask_firebase/templates/firebase_auth/production_widget.html

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "firebase_auth/widget_base.html" %}

flask_firebase/templates/firebase_auth/production_widget_base.html flask_firebase/templates/firebase_auth/widget_base.html

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{% block scripts %}{% endblock %}
99
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.3.0/firebaseui.css" />
1010
{% block styles %}{% endblock %}
11+
{% if firebase_auth.api_key %}
1112
<script>
1213
firebase.initializeApp({
1314
apiKey: "{{ firebase_auth.api_key }}",
@@ -38,10 +39,18 @@
3839
}
3940
});
4041
</script>
42+
{% endif %}
4143
</head>
4244
<body>
4345
{% block header %}{% endblock %}
4446
<div id="firebaseui-auth-container"></div>
47+
{% if firebase_auth.debug %}
48+
<h3>Development sign-in</h3>
49+
<form action="" method="POST">
50+
Email: <input type="text" name="email" />
51+
<input type="submit" value="Sign in" />
52+
</form>
53+
{% endif %}
4554
{# TODO: Default text explaining that you sign up by signing in. #}
4655
{% block footer %}{% endblock %}
4756
</body>

0 commit comments

Comments
 (0)