Barbar Service is a project for demo of simple distribute authentication Service.

Barbar Service

Barbar Service is a project for demo of simple distribute authentication Service.

Project Structure

Basicaly we reffer to Domain Driven Design and Clean Architecture for this code.

- cmd  // directory for handle command
    |- grpc_user.go
    |- ...
- config // directory for handle config
    |- config.go
- pkg // directory for internal utilities or wrapper 
    |- jwt
    |- middleware
    |- mongodb
    |- ...
- domain // directory for internal services of domain service
    |- auth // domain auth service
        |- entity // is a directory of code for the entity domain
        |- infrastructure // directory of code for handle dependencies to other service
        |- repository // for handle data story (example the service should be insert to mongodb)
        |- usecase // business logic or domain logic handle on here 
        |- tranport // directory of code for handle transport layer example (grpc, http)
    |- users // domain user service
- proto // is share file for proto onto the services
- .env // is a configuration file for running local
- .env_docker is a configuration file for running with docker
- main.go is a root running program to call functions of the cases

Tech Stack

  • Overall Basic Programming language use golang
  • Datastore with MongoDB
  • The Communication with HTTP Rest API (for external connection) and GRPC (internal connection)
  • Redis for caching model, for this case cache should be store valid Token

Service Design

alt text

Rules

After this program started without problem, we can hit the API for User-Service and Auth-Service.

  • Register
    • Email must be unique from other user has been registered
    • Password will be encrypt on database
    • Register don't use Token Authorization
  • Update User, Delete User, Get User By ID, Get All User
    • Must use Token Authorization
    • Token should be expired on 1 hour
    • We refer to RESTFull API for users endpoint
    • If you have error invalid token/token expired please login again for getting new token
  • Login
    • Don't use Token Authorization
    • Input valid email and password
    • Data should be store on auth database on mongo (for audit) and store on cache (redis)
  • Logout
    • Must use Token Authorization
    • Data should be update the user record and also clear redis record by userId

How to Run

Install and Run Program

  • install docker
  • run docker build
    $ docker build -t barbar .
  • run docker compose
    $ docker-compose up
  • run init index for mongodb
      $ docker run barbar:latest init-index-mongo

API with CURL

  • Register
curl --location --request POST 'localhost:3000/user-service/api/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Darto Test 1",
    "phone": "081131234",
    "email": "[email protected]",
    "password": "testing"
}'
  • Login
curl --location --request POST 'localhost:3001/auth-service/api/v1/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "testing"
}'
  • Logout
curl --location --request GET 'localhost:3001/auth-service/api/v1/logout' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QxQGVtYWlsLmNvbSIsInVzZXJJZCI6ImQ2MjEyOGVlLTA3OWMtNDU5MS04MmQ0LTg3NWU0NmZkODI2ZCIsImV4cCI6MTYzNDQ5NTc5MSwianRpIjoiNTkyM2U1MmMtOWQxOS00ZjJiLWFkODctN2QwYjc2NWIzNmJmIiwic3ViIjoidXNlciJ9.jq-kYrL_Xo92hzFSH2DlntjPfU8YV9_fW2ezX3QZuUA' \
--data-raw ''
  • Get User by Id
curl --location --request GET 'localhost:3000/user-service/api/v1/users/a80d3a5d-3452-4d6a-9ace-055bebcc9523' \
--header 'Authorization: Bearer  
   
    '
   
  • Get All User
curl --location --request GET 'localhost:3000/user-service/api/v1/users' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QxQGVtYWlsLmNvbSIsInVzZXJJZCI6ImQ2MjEyOGVlLTA3OWMtNDU5MS04MmQ0LTg3NWU0NmZkODI2ZCIsImV4cCI6MTYzNDU1Mzk2MSwianRpIjoiZjlmY2YwZDEtZGExNy00NGJlLTgzNzItNmEwN2UyODgwNzZlIiwic3ViIjoidXNlciJ9.k_Bdns2Aghk_5dPNXx0DgPlYc0Zt7W05oZ2JbRYJv-Q'
  • Update User
curl --location --request PUT 'localhost:3000/user-service/api/v1/users/a80d3a5d-3452-4d6a-9ace-055bebcc9523' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QxQGVtYWlsLmNvbSIsInVzZXJJZCI6ImQ2MjEyOGVlLTA3OWMtNDU5MS04MmQ0LTg3NWU0NmZkODI2ZCIsImV4cCI6MTYzNDQ5NTc5MSwianRpIjoiNTkyM2U1MmMtOWQxOS00ZjJiLWFkODctN2QwYjc2NWIzNmJmIiwic3ViIjoidXNlciJ9.jq-kYrL_Xo92hzFSH2DlntjPfU8YV9_fW2ezX3QZuUA' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Darto Test 1 Update",
    "phone": "081131233",
    "email": "[email protected]",
    "password": "testing"
}'
  • Delete User
curl --location --request DELETE 'localhost:3000/user-service/api/v1/users/e9d7353d-1c5c-4412-9a3b-62adb9bac02b' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QyQGVtYWlsLmNvbSIsInVzZXJJZCI6ImU5ZDczNTNkLTFjNWMtNDQxMi05YTNiLTYyYWRiOWJhYzAyYiIsImV4cCI6MTYzNDUwNzc4NSwianRpIjoiYjAwMWZiNzEtMzY4OC00YWNmLTg0ZWMtYjMxODI3OWVjZjc5Iiwic3ViIjoidXNlciJ9.qW8JX9Ifnx1ztKdB3DMvbWCtcNkPcD_ZE5UE7bpQrJQ'
Owner
Audy Vaksi Pranata
Audy Vaksi Pranata
Similar Resources

Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.

❗ Cache package has been moved to libcache repository Go-Guardian Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to

Dec 23, 2022

Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applications.

Goth: Multi-Provider Authentication for Go Package goth provides a simple, clean, and idiomatic way to write authentication packages for Go web applic

Dec 29, 2022

Simple authentication and books management with GoFiber

Simple authentication and books management with GoFiber Simple authentication system with gofiber. Endpoints GET /api - Welcome message POST /api/auth

Nov 27, 2022

Example of a simple application which is powered by a third-party oAuth 2.0 server for it's authentication / authorization. Written in Golang.

go mod init github.com/bartmika/osin-thirdparty-example go get github.com/spf13/cobra go get github.com/openshift/osin go get github.com/openshift/osi

Jan 4, 2022

A simple passwordless proxy authentication middleware using email.

A simple passwordless proxy authentication middleware using email.

email proxy auth A simple passwordless proxy authentication middleware that uses only email as the authentication provider. Motivation I wanted to res

Jul 27, 2022

A simple authentication web application in Golang (using jwt)

Simple Authentication WebApp A simple authentication web app in Go (using JWT) Routes Path Method Data /api/v1/auth/register POST {"firstname":,"lastn

Feb 6, 2022

Go login handlers for authentication providers (OAuth1, OAuth2)

Go login handlers for authentication providers (OAuth1, OAuth2)

gologin Package gologin provides chainable login http.Handler's for Google, Github, Twitter, Facebook, Bitbucket, Tumblr, or any OAuth1 or OAuth2 auth

Dec 30, 2022

HTTP Authentication middlewares

goji/httpauth httpauth currently provides HTTP Basic Authentication middleware for Go. It is compatible with Go's own net/http, goji, Gin & anything t

Dec 23, 2022

[DEPRECATED] Go package authcookie implements creation and verification of signed authentication cookies.

Package authcookie import "github.com/dchest/authcookie" Package authcookie implements creation and verification of signed authentication cookies. Co

Dec 22, 2022
A simple passwordless authentication middleware that uses only email as the authentication provider
A simple passwordless authentication middleware that uses only email as the authentication provider

email auth A simple passwordless authentication middleware that uses only email as the authentication provider. Motivation I wanted to restrict access

Jul 27, 2022
Authelia: an open-source authentication and authorization server providing two-factor authentication
Authelia: an open-source authentication and authorization server providing two-factor authentication

Authelia is an open-source authentication and authorization server providing two

Jan 5, 2022
Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication
Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication

Authentication Plugin for implementing Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0, SAML Authentication

Jan 8, 2023
A demo of authentication and authorization using jwt
A demo of authentication and authorization using jwt

Nogopy Hi, this a demo of how to use jwt for authentication in microservices Keep in mind that this is a demo of how to authenticate using jwt, we don

Nov 1, 2021
Vault Authentication Azure Auth Method Demo Application
Vault Authentication Azure Auth Method Demo Application

This application demonstrates how applications hosted on Azure VMs can use managed identity to authenticate with HashiCorp Vault using the Azure Auth Method.

Feb 10, 2022
A distribute SSO system

single-sign-on-system 一:SSO单点登录系统开发总结 (一):整体架构分析 基于go-oauth2/oauth2库实现的前端分离SSO单点登录系统 (二):系统技术点分析 当前系统的业务技术栈如下 Vue3 、ElementUI 作为前端页面 Nginx 用于解决系统之间的跨域

Aug 9, 2022
Authentication service that keeps you in control without forcing you to be an expert in web security.
Authentication service that keeps you in control without forcing you to be an expert in web security.

Authentication service that keeps you in control without forcing you to be an expert in web security.

Jan 1, 2023
An imaginary authentication and session tracking service that is defined in this Apiary

Userland This repository contains impelementation of "Userland" on boarding project Userland is an imaginary authentication and session tracking servi

Dec 5, 2021
AuthService is a service that provides authentication with Minecraft Mojang.

AuthService AuthService is a service that provides authentication with Minecraft Mojang. Protobuf is managed by Buf. Command to pull Protobuf files wi

Aug 20, 2022
Server bridging Google's OAuth and service using Radius for authentication

Fringe Fringe is an easy workaround for Google Workplace users who need a Radius server to perform authentication on behalf of other services (e.g. 80

Mar 7, 2022