Explorar o código

feature: local auth! (#441)

* feature: local auth!

* cicd: contentLogin -> content-login

* bugfix: CSS codestyle
James Read hai 1 ano
pai
achega
71ad5d2e3a
Modificáronse 4 ficheiros con 70 adicións e 0 borrados
  1. 16 0
      OliveTin.proto
  2. 12 0
      internal/config/config.go
  3. 13 0
      internal/grpcapi/grpcApi.go
  4. 29 0
      webui.dev/index.html

+ 16 - 0
OliveTin.proto

@@ -209,6 +209,15 @@ message KillActionResponse {
 	bool found = 4;
 	bool found = 4;
 }
 }
 
 
+message LocalUserLoginRequest {
+    string username = 1;
+    string password = 2;
+}
+
+message LocalUserLoginResponse {
+    string authenticated_user = 1;
+}
+
 service OliveTinApiService {
 service OliveTinApiService {
 	rpc GetDashboardComponents(GetDashboardComponentsRequest) returns (GetDashboardComponentsResponse) {
 	rpc GetDashboardComponents(GetDashboardComponentsRequest) returns (GetDashboardComponentsResponse) {
 		option (google.api.http) = {
 		option (google.api.http) = {
@@ -298,4 +307,11 @@ service OliveTinApiService {
 			get: "/api/readyz"
 			get: "/api/readyz"
 		};
 		};
 	}
 	}
+
+    rpc Authenticate(LocalUserLoginRequest) returns (LocalUserLoginResponse) {
+        option (google.api.http) = {
+            post: "/api/authenticate"
+            body: "*"
+        };
+    }
 }
 }

+ 12 - 0
internal/config/config.go

@@ -115,6 +115,7 @@ type Config struct {
 	AuthJwtPubKeyPath               string // will read pub key from file on disk
 	AuthJwtPubKeyPath               string // will read pub key from file on disk
 	AuthHttpHeaderUsername          string
 	AuthHttpHeaderUsername          string
 	AuthHttpHeaderUserGroup         string
 	AuthHttpHeaderUserGroup         string
+	AuthUsernamePassword            AuthUsernamePasswordConfig
 	AuthLoginUrl                    string
 	AuthLoginUrl                    string
 	AuthAllowGuest                  bool
 	AuthAllowGuest                  bool
 	AuthOAuth2RedirectURL           string
 	AuthOAuth2RedirectURL           string
@@ -139,6 +140,17 @@ type Config struct {
 	usedConfigDir string
 	usedConfigDir string
 }
 }
 
 
+type AuthUsernamePasswordConfig struct {
+	Enabled bool
+	Users   []*LocalUser
+}
+
+type LocalUser struct {
+	Username string
+	Password string
+	Groups   []string
+}
+
 type OAuth2Provider struct {
 type OAuth2Provider struct {
 	Name          string
 	Name          string
 	Title         string
 	Title         string

+ 13 - 0
internal/grpcapi/grpcApi.go

@@ -94,6 +94,19 @@ func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *pb.StartActionRequest)
 	}, nil
 	}, nil
 }
 }
 
 
+func (api *oliveTinAPI) Authenticate(ctx ctx.Context, req *pb.LocalUserLoginRequest) (*pb.LocalUserLoginResponse, error) {
+/*
+	user := acl.Authenticate(cfg, req.Username, req.Password)
+
+	if user == nil {
+		return nil, status.Errorf(codes.Unauthenticated, "Invalid username or password.")
+	}
+*/
+
+	return &pb.LocalUserLoginResponse{
+	}, nil
+}
+
 func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *pb.StartActionAndWaitRequest) (*pb.StartActionAndWaitResponse, error) {
 func (api *oliveTinAPI) StartActionAndWait(ctx ctx.Context, req *pb.StartActionAndWaitRequest) (*pb.StartActionAndWaitResponse, error) {
 	args := make(map[string]string)
 	args := make(map[string]string)
 
 

+ 29 - 0
webui.dev/index.html

@@ -92,6 +92,35 @@
 				</fieldset>
 				</fieldset>
 			</section>
 			</section>
 
 
+			<section id = "content-login" title = "Login" hidden>
+				<div class = "flex-col">
+				<form class = "box-shadow padded-content">
+					<h2>OAuth Login</h2>
+					<div>
+						<button>GitHub</button>
+						<button>Google</button>
+					</div>
+					<hr />
+					<h2>Local Login</h2>
+					<div class = "arguments">
+						<label for = "username">
+							<span>Username:</span>
+						</label>
+						<input type = "text" name = "username" />
+						<span></span>
+
+						<label for = "password">
+							<span>Password:</span>
+						</label>
+						<input type = "password" name = "password" />
+						<span></span>
+
+						<button type = "submit">Login</button>
+					</div>
+				</form>
+				</div>
+			</section>
+
 			<noscript>
 			<noscript>
 				<div class = "error">Sorry, JavaScript is required to use OliveTin.</div>
 				<div class = "error">Sorry, JavaScript is required to use OliveTin.</div>
 			</noscript>
 			</noscript>