Skip to content

Commit

Permalink
0.6.3: fix: auth uid property, small dev workflow & doc improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Feb 15, 2023
1 parent bc1cf1f commit 2fbb983
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker/build/prod: ## [Local development] Build the docker image.
docker buildx build . --platform linux/amd64 -t ${IMAGE_URL} -f ./docker/Dockerfile

docker/run/dev: ## [Local development] Run the development docker image.
docker-compose up
docker-compose up --build

docker/run/prod:
# note we don't use buildx here to use local platform cpu
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Right now we just support simple firebase auth. We'll be adding more integration

`config.yaml`
```
authentication: firebase
auth: firebase
# make sure to have "service_account.json" at this path
firebase_service_account_path: ./service_account.json
```

Expand Down
8 changes: 5 additions & 3 deletions embedbase/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
PORT = os.environ.get("PORT", 8080)
UPLOAD_BATCH_SIZE = int(os.environ.get("UPLOAD_BATCH_SIZE", "100"))

logger = logging.getLogger("search")
logger = logging.getLogger("embedbase")
logger.setLevel(settings.log_level)
handler = logging.StreamHandler()
handler.setLevel(settings.log_level)
Expand Down Expand Up @@ -64,6 +64,7 @@
)

if settings.auth == "firebase":
logger.info("Enabling Firebase Auth")
from firebase_admin import auth

@app.middleware("http")
Expand Down Expand Up @@ -97,11 +98,12 @@ async def firebase_auth(request: Request, call_next) -> Tuple[str, str]:
try:
token = token.strip()
decoded_token = auth.verify_id_token(token)
# add uid to scope
request.scope["uid"] = decoded_token["uid"]
except Exception as err:
logger.warning(f"Error verifying token: {err}")
return JSONResponse(status_code=401, content={"error": "invalid token"})

# add uid to scope
request.scope["uid"] = decoded_token["userId"]
response = await call_next(request)
return response

Expand Down
13 changes: 13 additions & 0 deletions examples/simple-react-auth/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.7'

services:
embedbase:
image: ghcr.io/another-ai/embedbase:latest
ports:
- "8000:8000"
environment:
- PYTHONUNBUFFERED=1
- PORT=8000
volumes:
- ./config.yaml:/app/config.yaml
- ./svc.prod.json:/secrets_firebase/svc.prod.json
15 changes: 6 additions & 9 deletions examples/simple-react-auth/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { GoogleAuthProvider, signInWithPopup } from "firebase/auth";
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();
const hashCode = (s: string) => s.split('').reduce((a, b) => (((a << 5) - a) + b.charCodeAt(0))|0, 0)

// read firebase config from fb.json
const firebaseConfig = require('./fb.json');
const app = initializeApp(firebaseConfig);

initializeApp(firebaseConfig);
const BASE_URL = 'http://0.0.0.0:8000';
const VAULT_ID = 'dev';
function App() {
const [search, setSearch] = React.useState('');
const [documents, setDocuments] = React.useState<{data: string; color: string}[]>([]);
Expand All @@ -28,7 +25,7 @@ function App() {
}
const colourizeDocuments = () => {
if (!search) return;
fetch('http://localhost:8000/v1/dev/search', {
fetch(`${BASE_URL}/v1/${VAULT_ID}/search`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -50,7 +47,7 @@ function App() {
}).catch((err) => alert(err));
};
const addDocument = () => {
fetch('http://localhost:8000/v1/dev', {
fetch(`${BASE_URL}/v1/${VAULT_ID}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -65,7 +62,7 @@ function App() {
.catch((err) => alert(err));
}
const clearIndex = () => {
fetch('http://localhost:8000/v1/dev/clear', {
fetch(`${BASE_URL}/v1/${VAULT_ID}/clear`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
name="embedbase",
packages=find_packages(),
include_package_data=True,
version="0.6.2",
version="0.6.3",
description="Open-source API for to easily create, store, and retrieve embeddings",
install_requires=install_requires,
extras_require=extras_require,
Expand Down

0 comments on commit 2fbb983

Please sign in to comment.