Skip to content

feat: identity provider functions #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ disable=abstract-method,
wrong-import-order,
xrange-builtin,
zip-builtin-not-iterating,
import-outside-toplevel,


[REPORTS]
Expand Down
1 change: 1 addition & 0 deletions docs/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ PY_MODULES='firebase_functions
firebase_functions.core
firebase_functions.db_fn
firebase_functions.https_fn
firebase_functions.identity_fn
firebase_functions.options
firebase_functions.params
firebase_functions.pubsub_fn
Expand Down
5 changes: 5 additions & 0 deletions samples/identity/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "python-functions-testing"
}
}
66 changes: 66 additions & 0 deletions samples/identity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
3 changes: 3 additions & 0 deletions samples/identity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Required to avoid a 'duplicate modules' mypy error
# in monorepos that have multiple main.py files.
# https://github.com/python/mypy/issues/4008
24 changes: 24 additions & 0 deletions samples/identity/client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.19.1/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.19.1/firebase-auth.js";

const firebaseConfig = {
apiKey: "AIzaSyCZ2C2_0jQIkQItbiJ4IGbL8OLObbK2mY0",
authDomain: "python-functions-testing.firebaseapp.com",
databaseURL: "https://python-functions-testing-default-rtdb.europe-west1.firebasedatabase.app",
projectId: "python-functions-testing",
storageBucket: "python-functions-testing.appspot.com",
messagingSenderId: "441947996129",
appId: "1:441947996129:web:227004b738ba64f04edca0",
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

// createUserWithEmailAndPassword(auth, "hello@dogs.com", "password")
signInWithEmailAndPassword(auth, "hello@cats.com", "password")
.then((userCredential) => {
console.log("signed in", userCredential);
})
.catch(console.error);
</script>
11 changes: 11 additions & 0 deletions samples/identity/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"venv"
]
}
]
}
13 changes: 13 additions & 0 deletions samples/identity/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pyenv
.python-version

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Environments
.env
.venv
venv/
venv.bak/
__pycache__
41 changes: 41 additions & 0 deletions samples/identity/functions/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Firebase Cloud Functions for blocking auth functions example."""
from firebase_functions import identity_fn


@identity_fn.before_user_created(
id_token=True,
access_token=True,
refresh_token=True,
)
def beforeusercreated(
event: identity_fn.AuthBlockingEvent
) -> identity_fn.BeforeCreateResponse | None:
print(event)
if not event.data.email:
return None
if "@cats.com" in event.data.email:
return identity_fn.BeforeCreateResponse(display_name="Meow!",)
if "@dogs.com" in event.data.email:
return identity_fn.BeforeCreateResponse(display_name="Woof!",)
return None


@identity_fn.before_user_signed_in(
id_token=True,
access_token=True,
refresh_token=True,
)
def beforeusersignedin(
event: identity_fn.AuthBlockingEvent
) -> identity_fn.BeforeSignInResponse | None:
print(event)
if not event.data.email:
return None

if "@cats.com" in event.data.email:
return identity_fn.BeforeSignInResponse(session_claims={"emoji": "🐈"})

if "@dogs.com" in event.data.email:
return identity_fn.BeforeSignInResponse(session_claims={"emoji": "🐕"})

return None
8 changes: 8 additions & 0 deletions samples/identity/functions/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Not published yet,
# firebase-functions-python >= 0.0.1
# so we use a relative path during development:
./../../../
# Or switch to git ref for deployment testing:
# git+https://github.com/firebase/firebase-functions-python.git@main#egg=firebase-functions

firebase-admin >= 6.0.1
Loading