Skip to content

its a repository for challenge about jwt auth in golang

Notifications You must be signed in to change notification settings

ainmtsn1999/orm_jwt_auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ORM JWT AUTH

it's a jwt authorization implementation. Here's a API flow task details:

Buatlah Rest API product (create, read, update, delete) dengan fitur login dan register, serta memiliki 3 fitur middleware antara lain :
- Authentication
- Authorization multi level user
- Authorization access product by id

Notes : buatlah authentication dengan JWT token golang, lalu gunakan token tersebut untuk setiap hit Rest API product.

Documentation

POST users/register

it's a register user endpoint. This endpoint can be accessed by everyone.

Request Body :

{
    "fullname" : "string",
    "email" : "string", # must be a valid email
    "password" : "string",
	"role" : "string" #must be a valid role, but omitempty
}

Notes : On this endpoint, password will be hashed using crypto library

Response Body :

  • success response: Screenshot 2023-04-09 072413

  • failed response: Screenshot 2023-04-09 072256

POST users/login

it's a login user endpoint. This endpoint can be accessed by everyone.

Request Body :

{
    "email" : "string", # must be a valid email
    "password" : "string",
}

Response Body :

  • success response: Screenshot 2023-04-09 072545

  • failed response: Screenshot 2023-04-09 072505

POST products

it's a create product endpoint. This endpoint only can be accessed by admin and user.

Request Headers

Authorization : Bearer <token>

Request Body :

{
    "title" : "string",
    "description" : "string",
}

Response Body :

  • success response: Screenshot 2023-04-09 072704

  • failed response: Screenshot 2023-04-09 074246

PUT products/:productId

it's a update product endpoint. This endpoint only can be accessed by admin.

Params

  • productId : int | required

Request Headers

Authorization : Bearer <token>

Request Body :

{
    "title" : "string",
    "description" : "string",
}

Response Body :

  • success response: Screenshot 2023-04-09 073327

  • failed response: Screenshot 2023-04-09 072842 Screenshot 2023-04-09 074152

DELETE products/:productId

it's a delete product endpoint. This endpoint only can be accessed by admin.

Params

  • productId : int | required

Request Headers

Authorization : Bearer <token>

Response Body :

  • success response: Screenshot 2023-04-09 073730

  • failed response: Screenshot 2023-04-09 073806

GET products

it's a get all product {by userId jwt} endpoint. This endpoint only can be accessed by admin and user.

Request Headers

Authorization : Bearer <token>

Response Body :

  • success response: Screenshot 2023-04-09 073044 Screenshot 2023-04-09 073235

  • failed response: Screenshot 2023-04-09 074246

GET products/:productId

it's a get product by productId endpoint. This endpoint only can be accessed by admin and user.

Params

  • productId : int | required

Request Headers

Authorization : Bearer <token>

Response Body :

  • success response: Screenshot 2023-04-09 072926

  • failed response: Screenshot 2023-04-09 073000

About

its a repository for challenge about jwt auth in golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages