Skip to content

Auth microservice written in Go, provides gRPC endpoints for managing JWT tokens and user's data

Notifications You must be signed in to change notification settings

martishin/auth-server

Repository files navigation

Auth Server

Authentication/Authorization microservice written in Go, provides gRPC endpoints for managing JWT tokens and user's data.

Running Locally

  • To run the server and PostgreSQL locally you can execute:
    make run
  • To stop them, run:
    make down
  • Alternatively you can start the database and apply migrations by running:
    make run-postgres DETACHED=true && make migrate
  • And then start a server:
    go run cmd/sso/main.go --config=./configs/local.yaml
  • API will be available at http://localhost:8080/

Testing

  • Run tests: make test

How to Connect From Another Service

  • Fetch schemas from the auth-server-schemas repo:
    go get github.com/tty-monkey/auth-server-schemas
  • Create a client connection:
cc, err := grpc.DialContext(context.Background(),
	net.JoinHostPort(grpcHost, grpcPort),
	grpc.WithTransportCredentials(insecure.NewCredentials()),
)
  • Initialize a client:
authClient := ssov1.NewAuthClient(cc)
  • Make requests using the client:
resp, err := authClient.Register(ctx, &ssov1.RegisterRequest{
  Email:    email,
  Password: password,
})

Endpoints

gRPC protobuf schemas can be found here. You can import the schema file into Postman and send requests from it.

Auth / Register

Registers a new user.

  • Request: RegisterRequest

    • email (string): User's email address.
    • password (string): User's password.
  • Response: RegisterResponse

    • user_id (int64): Unique identifier of the registered user.

Auth / Login

Authenticates a user and provides a token.

  • Request: LoginRequest

    • email (string): User's email address.
    • password (string): User's password.
    • app_id (int32): Application identifier.
  • Response: LoginResponse

    • token (string): Authentication token for the user.

Auth / IsAdmin

Checks if the user is an admin.

  • Request: IsAdminRequest

    • user_id (int64): Unique identifier of the user.
  • Response: IsAdminResponse

    • is_admin (bool): Indicates whether the user is an admin.

Technologies/Packages Used