Giter Site home page Giter Site logo

jottenlips / tinyauth Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 4.05 MB

๐Ÿ“ฑ A tiny passwordless SMS authentication service using Flask, JWT, Serverless, DynamoDB, Ariadne GraphQL

Home Page: https://tinyauth.io/graphql

License: MIT License

Python 100.00%
sms authentication tinyauth graphql python ariadne serverless dynamodb sns boto3

tinyauth's Introduction

tinyauth is a very tiny passwordless GraphQL authentication service. tinyauth keeps authentication simple with 3 easy steps.

(This is a toy, don't use for production)

Step 1

  • sends code to user's phone
mutation {
  sendVerification(phone: "+15559993478", message: "Howdy! your code is") {
    status # 200
    message # verification sent
    success # true
  }
}

Step 2

  • verify phone with code user received as sms
mutation {
  verifyUser(verification: { phone: "+15559993478", code: "555555" }) {
    status
    message
    success
    auth # auth jwt to include in future headers
  }
}

Step 3

  • place jwt in headers {"auth": "auth-jwt-from-last-step"}

  • run the getMe query

{
  getMe {
    id
    phone
  }
}

Develop

Set up your .aws credentials, make a DynamoDB table named tinyauth-dev

Install node (to run serverless-offline). I use nvm to manage my node versions.

Go to your tinyauth-api folder:

touch .env

Add TABLE_NAME and API_SECRET environment variables.

TABLE_NAME=my-app-dev
API_SECRET=somethingsecret

npm install

virtualenv -p python3 venv

source venv/bin/activate

pip install -r requirements.txt

sls deploy - will automatically make your dynamodb table on aws.

sls wsgi serve -p 8000 or yarn run start

Run queries in Graphi at http://localhost:8000/graphql

Run Tests

TABLE_NAME=tinyauth-test API_SECRET=somethingsecret python -m pytest or yarn run test

Deploy

Update your table name / secret in .env and run

sls deploy

No GraphQL Client?

Send verification

import requests

variables = {'phone': '+155555555555'}
mutation = """
mutation SendVerification($phone: String!) {
  sendVerification(phone: $phone) {
    status
    message
    success
  }
}
"""

# or localhost:8000 for dev
requests.post('https://tinyauth.io/graphql', json={'query': mutation, 'variables': variables})

Verify user

import requests

variables = {'phone': '+155555555555', 'code': '555555'}
mutation = """
mutation VerifyUser($phone: String!, $code: String!) {
  verifyUser(verification: { phone: $phone, code: $code }) {
    status
    message
    success
    auth # auth jwt to include in future headers
  }
}
"""

# or localhost:8000 for dev
requests.post('https://tinyauth.io/graphql', json={'query': mutation, 'variables': variables})

Get Me

import requests

headers = {
  "auth": your-tinyauth-jwt
}

query = """
{
  getMe {
    id
    phone
  }
}
"""

# or localhost:8000 for dev
requests.post('https://tinyauth.io/graphql', json={'query': query}, headers=headers)

tinyauth's People

Contributors

jottenlips avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.