module
0.0.0-20241122111047-01065b008a77
Repository: https://github.com/tty-monkey/auth-server.git
Documentation: pkg.go.dev
# README
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,
})
- Usage examples can be found in e2e tests
Endpoints
gRPC protobuf schemas can be found here. You can import the schema file into Postman and send requests from it.
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.
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.
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.