Skip to content

Commit

Permalink
Allow to use Firebase Auth in debug mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
keosak committed Sep 14, 2017
1 parent e746bf0 commit 7a0928f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
33 changes: 11 additions & 22 deletions flask_firebase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def __init__(self, app=None):
def init_app(self, app):
app.extensions['firebase_auth'] = self
self.debug = app.debug
if self.debug:
self.api_key = app.config.get('FIREBASE_API_KEY')
if self.api_key is None:
return
self.api_key = app.config['FIREBASE_API_KEY']
self.project_id = app.config['FIREBASE_PROJECT_ID']
self.server_name = app.config['SERVER_NAME']
provider_ids = []
Expand All @@ -86,31 +86,20 @@ def unloader(self, callback):
return callback

def url_for(self, endpoint, **values):
full_endpoint = 'firebase_auth.{}'.format(endpoint)
if self.debug:
return url_for(full_endpoint, **values)
else:
return url_for(
full_endpoint,
_external=True,
_scheme='https',
**values)
return url_for(
'firebase_auth.{}'.format(endpoint),
_external=True,
_scheme='http' if self.debug else 'https',
**values)

def widget(self):
next_ = self.verify_redirection()
if self.debug:
if request.method == 'POST':
self.development_load_callback(request.form['email'])
return redirect(next_)
else:
return render_template('firebase_auth/development_widget.html')
else:
return render_template(
'firebase_auth/production_widget.html',
firebase_auth=self)
if self.debug and request.method == 'POST':
self.development_load_callback(request.form['email'])
return redirect(next_)
return render_template('firebase_auth/widget.html', firebase_auth=self)

def sign_in(self):
assert not self.debug
header = jwt.get_unverified_header(request.data)
with self.lock:
self.refresh_keys()
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions flask_firebase/templates/firebase_auth/widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "firebase_auth/widget_base.html" %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% block scripts %}{% endblock %}
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.3.0/firebaseui.css" />
{% block styles %}{% endblock %}
{% if firebase_auth.api_key %}
<script>
firebase.initializeApp({
apiKey: "{{ firebase_auth.api_key }}",
Expand Down Expand Up @@ -38,10 +39,18 @@
}
});
</script>
{% endif %}
</head>
<body>
{% block header %}{% endblock %}
<div id="firebaseui-auth-container"></div>
{% if firebase_auth.debug %}
<h3>Development sign-in</h3>
<form action="" method="POST">
Email: <input type="text" name="email" />
<input type="submit" value="Sign in" />
</form>
{% endif %}
{# TODO: Default text explaining that you sign up by signing in. #}
{% block footer %}{% endblock %}
</body>
Expand Down

0 comments on commit 7a0928f

Please sign in to comment.