Git Product home page Git Product logo

facenet-oauth-server's Introduction

Oauth Server with FaceNet identification

A PoC OAuth server that uses face detection (based on FaceNet) instead of username/password to identify users.

Setup

Python (3.8) environment Setup

# install PyTorch
pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

Generate embedding vectors

# cd into training directory
cd training

# install python packages
pip install -r requirements.txt

# copy one training image per person into training_images directory
# the structure should look something like
training_images
└───John
│   │   image.jpg
|
└───Jane
    │   image.jpg

# copy one test image per person (should be different that the one used for training) into test_images directory
# the structure should look something like
test_images
└───John
│   │   alternative_image.jpg
|
└───Jane
    │   alternative_image.jpg    

# generate embeddings and names
python set_embeddings.py

# test embeddings and names
python test_detection.py

# copy embeddings and names to server directory (flask version)
cp embeddings.pt ../server/flask/embeddings.pt
cp names.npy ../server/flask/names.npy

# copy embeddings and names to server directory (azure functions version)
cp embeddings.pt ../server/azure_functions/common/embeddings.pt
cp names.npy ../server/azure_functions/common/names.npy

Generate RSA keys

# cd into server directory
cd server

# prepare private key (do not specify passphrase)
openssl genrsa -out private.pem 2048

# prepare public key
openssl rsa -in private.pem -pubout -outform PEM -out public.pem

# prepare jwk file
npm install -g pem-jwk
pem-jwk public.pem > public.jwk

# copy files to server directory (flask version)
cp public.jwk ../server/flask/private.pem
cp public.jwk ../server/flask/public.jwk

# copy files to server directory (azure functions version)
cp public.jwk ../server/azure_functions/common/private.pem
cp public.jwk ../server/azure_functions/jwks/public.jwk

Configure OTP

# cd into server directory
cd server

# run interactive python prompt
python

# execute the following:
import pyotp
pyotp.random_base32()  # note the return value and use this to configure your authenticator App

# update USER_OTP_SECRETS in config.py under DevelopmentConfig (in flask folder)
USER_OTP_SECRETS = { 'YourUsername': 'ValueReturnedByPyOTP' }

# update USER_OTP_SECRETS in local.settings.json (in azure_functions folder)
USER_OTP_SECRETS = { \"YourUsername\": \"ValueReturnedByPyOTP\" }

Run Server

Flask Server

# cd into server directory
cd server/flask

# install python packages
pip install -r requirements.txt

# set environment (production or development)
export FLASK_ENV=development

# serve with hot reload at 127.0.0.1:5001
python server.py

Azure Functions Server

Ensure you have Azure Function tools installed

# cd into server directory
cd server/azure_functions

# install python packages
pip install -r requirements.txt

func host start --cors *

Building Flask Server Docker image

# run from root directory, replace <environment> with development or production
docker build --build-arg FLASK_ENV=<environment> -t facenet-oauth-server -f server/Dockerfile .

Run Client

To run against Flask version of API follow these steps:

# cd into client directory
cd client

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

To target Azure functions API go to main.js and modify authority setting with functions base url.

facenet-oauth-server's People

Contributors

ayls avatar dependabot[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.