Files
2026-09-13 14:02:47 +01:00

80 lines
2.1 KiB
Go

// Code generated by protoc-gen-go-http. DO NOT EDIT.
// source: auth.proto
package httppb
import (
"net/http"
"github.com/effective-security/porto/restserver"
"github.com/effective-security/porto/xhttp/correlation"
"github.com/effective-security/porto/xhttp/httperror"
"github.com/effective-security/porto/xhttp/marshal"
"github.com/effective-security/trustyca/api/pb"
"google.golang.org/protobuf/types/known/emptypb"
)
// GetAuthHTTPHandler handles HTTP requests for Auth service
func GetAuthHTTPHandler(s pb.AuthServer, withAccessCheck pb.CheckAccessFunc) restserver.Handle {
return func(w http.ResponseWriter, r *http.Request, p restserver.Params) {
action := r.URL.Path
ctx := correlation.WithMetaFromRequest(r)
var err error
var res any
req, _, err := pb.UnmarshalRequest(w, r)
if err != nil {
// UnmarshalRequest already writes error response
return
}
if withAccessCheck != nil {
err = withAccessCheck(ctx, req, action)
if err != nil {
marshal.WriteJSON(w, r, err)
return
}
}
switch action {
case pb.Auth_GetProviders_FullMethodName:
res, err = s.GetProviders(ctx, req.(*pb.AuthProvidersRequest))
case pb.Auth_GetUserToken_FullMethodName:
res, err = s.GetUserToken(ctx, req.(*emptypb.Empty))
case pb.Auth_RevokeToken_FullMethodName:
res, err = s.RevokeToken(ctx, req.(*emptypb.Empty))
case pb.Auth_Caller_FullMethodName:
res, err = s.Caller(ctx, req.(*emptypb.Empty))
case pb.Auth_ExchangeCode_FullMethodName:
res, err = s.ExchangeCode(ctx, req.(*pb.ExchangeCodeRequest))
case pb.Auth_SelectOrg_FullMethodName:
res, err = s.SelectOrg(ctx, req.(*pb.SelectOrgRequest))
case pb.Auth_AuthenticateAPIKey_FullMethodName:
res, err = s.AuthenticateAPIKey(ctx, req.(*emptypb.Empty))
case pb.Auth_GetAllowedMethods_FullMethodName:
res, err = s.GetAllowedMethods(ctx, req.(*emptypb.Empty))
case pb.Auth_GetCallerScope_FullMethodName:
res, err = s.GetCallerScope(ctx, req.(*emptypb.Empty))
default:
err = httperror.Malformed("invalid action: %s", action)
}
if err != nil {
marshal.WriteJSON(w, r, err)
return
}
marshal.WriteJSON(w, r, res)
}
}