authservice

package
v0.0.0-...-0ac7419 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 9 Imported by: 0

README

Authentication Microservice. [REST]

JWT

I will create my own JWT for authentication. This requires a key. H256 algo will be used to generate the signature.

Link for the Article

JWT has the following components

  1. Header [base64 encoded]
  2. Payload [base64 encoded]
  3. Signature [combination of header and payload hashed using a private key]

Swagger

This will be used for Documenting the API

Schema for the User

  1. Email
  2. Full Name
  3. Password hash
  4. Username
  5. CreateDate

Things Learnt[Covered in Article] :-

  1. Using Gorilla MUX for Routing and Subroutes
  2. Implementing my own JWT Logic
  3. Creation of Modules and handling module specific data
  4. Writing Handlers for Sign In and Sign Up
  5. Creating Middleware
  6. Containerize the Application using Docker

Running the Hashed Command

curl http://localhost:9090/auth/signin --header 'Email:abc@gmail.com' --header 'Passwordhash:hashedme1'

curl http://localhost:9090/auth/signup --request POST --header 'Email:newuser@example.com' --header 'Passwordhash:hashedme1' --header 'Username:user77' --header 'Fullname:test user'

Documentation

Overview

Package Authentication of Product API

Documentation for Authentication of Product API

Schemes : http BasePath : /auth Version : 1.0.0

Consumes:

  • application/json

Produces:

  • application/json

swagger:meta

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SigninController

type SigninController struct {
	// contains filtered or unexported fields
}

SigninController is the Signin route handler

func NewSigninController

func NewSigninController(logger *zap.Logger) *SigninController

NewSigninController returns a frsh Signin controller

func (*SigninController) SigninHandler

func (ctrl *SigninController) SigninHandler(rw http.ResponseWriter, r *http.Request)

This will be supplied to the MUX router. It will be called when signin request is sent if user not found or not validates, returns the Unauthorized error if found, returns the JWT back. [How to return this?]

type SignupController

type SignupController struct {
	// contains filtered or unexported fields
}

SignupController is the Signup route handler

func NewSignupController

func NewSignupController(logger *zap.Logger) *SignupController

NewSignupController returns a frsh Signup controller

func (*SignupController) SignupHandler

func (ctrl *SignupController) SignupHandler(rw http.ResponseWriter, r *http.Request)

adds the user to the database of users

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL