GithubHelp home page GithubHelp logo

auth's Introduction

In-App Cloud Auth Build Status

An authentication microservice. You can use it directly as a REST API or use the package as part of your Go web application. It is built with Goji and requires PostgreSQL. cmd/auth-server/main.go will show you how to use the package in your own code.

API

It uses JSON API for request and response format.

Creating a user

To create a user, you need the following information:

name type description
email string Required. A valid email
password string Required. A password

Then you can make a request like this:

POST /users
Content-Type: application/json
Accept: application/json

{
  "data": [{
    "email": "[email protected]",
    "password": "p@ssw0rd"
  }]
}

Endpoint will respond with 400 Bad Request if the body is not JSON and with 422 Unprocessable Entity if the body has invalid formatting or params.

Log in

It's almost the same as user creation, the only change is the URI.

POST /sessions
Content-Type: application/json
Accept: application/json

{
  "data": [{
    "email": "[email protected]",
    "password": "p@ssw0rd"
  }]
}

Current user

You must set the Authorization header with value Bearer token where token is the value you will get from the other endpoints.

GET /users/me
Accept: application/json
Authorization: Bearer jnshionefv2r3rnvdfoi239

Response for all endpoints

name type description
id int User ID
email string User Email
token string A JWT token
{
  "data": [{
    "id": 1,
    "email": "[email protected]",
    "token": "jnshionefv2r3rnvdfoi239"
  }]
}

Endpoint will respond with 401 Unauthorized if the token is invalid.

Run

Locally

make setup
make server

If you have a custom environment for PostgreSQL, please update variable DATABASE_URL in file .env. It runs on port 8080 by default but you can add PORT in .env to change the port.

Test

make

If you have a custom environment for PostgreSQL, please update TEST_DB in file Makefile.

FAQ

Is it ready for production?

No. It need more testing, refinements and features before a real release.

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.