Coder Social home page Coder Social logo

golang-oauth-password-grant's Introduction

OAuth 2 Password Grant Type in Golang

Implementation of standard OAuth V2 for Password Grant type in Golang and its native HTTP server.

Clients API

POST  oauth2/clients HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/json

Request:

curl -k --location --request POST 'https://127.0.0.1:8080/oauth2/clients' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "johndoe1",
    "password": "johnspassword1"
}'

Response:

{
  "client_id": "a9a6b145-fafe-415c-a92e-c79cbd57567d"
}

Token API

POST  oauth2/token HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: application/x-www-form-urlencoded

Request:

curl -k --location --request POST 'https://127.0.0.1:8080/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=johndoe1' \
--data-urlencode 'password=johnspassword1'

Response:

{
  "access_token": "MmVjZGFiNmY4Y2E2OTQ1ZWNmMGQyNmZlODZhYWM5YzFhNDliYzZiNzNkNmY2MjBmYThiMzM3NTEyODE1ZTc1YjNiZTcxODI3YjFjZDkzZDYyODRkODljZjdjMDU3NWY4M2Y2NjdiODg4ZTliZDIwMzlmMTRlYjkxZGEyYmFkMDM=",
  "token_type": "Bearer",
  "expires_in": 3600
}

Up & Running

  make deploy

Debug

In order to run debugger you could create a config on your IDE and enable DEBUG env variable in your local environment. You will need database & cache storage from docker; you could enable them with:

  make debug

img

Todos

  • SSL For Postgres
  • SSL & Password for Redis
  • Cert for Creation of Token (Could be from Infra or Inside the code)
  • TLS Server Listener
  • Use Docker Secret to share passwords

Credits

Author: Hadi Tajallaei

Copyright © 2023 Syniol Limited. All rights reserved.

Please see a LICENSE file

golang-oauth-password-grant's People

Watchers

 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.