cleanups for OAuth in sdk.ShareRequest (#404)

This commit is contained in:
Michael Quigley 2023-09-28 13:06:00 -04:00
parent 957e50412e
commit 27fcf98fbd
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 9 additions and 10 deletions

View File

@ -83,7 +83,7 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
req := &sdk.ShareRequest{
BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: shareMode,
Auth: cmd.basicAuth,
BasicAuth: cmd.basicAuth,
Target: target,
}
if shareMode == sdk.PublicShareMode {

View File

@ -99,7 +99,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
req := &sdk.ShareRequest{
BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: sdk.PrivateShareMode,
Auth: cmd.basicAuth,
BasicAuth: cmd.basicAuth,
Target: target,
}
shr, err := sdk.CreateShare(root, req)

View File

@ -105,10 +105,9 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: sdk.PublicShareMode,
Frontends: cmd.frontendSelection,
Auth: cmd.basicAuth,
BasicAuth: cmd.basicAuth,
Target: target,
}
if cmd.oauthProvider != "" {
req.OauthProvider = cmd.oauthProvider
req.OauthEmailDomains = cmd.oauthEmailDomains

View File

@ -22,9 +22,9 @@ const (
type ShareRequest struct {
BackendMode BackendMode
ShareMode ShareMode
Frontends []string
Auth []string
Target string
Frontends []string
BasicAuth []string
OauthProvider string
OauthEmailDomains []string
OauthAuthorizationCheckInterval time.Duration

View File

@ -26,14 +26,14 @@ func CreateShare(root env_core.Root, request *ShareRequest) (*Share, error) {
return nil, errors.Errorf("unknown share mode '%v'", request.ShareMode)
}
if len(request.Auth) > 0 {
if len(request.BasicAuth) > 0 {
out.Body.AuthScheme = string(Basic)
for _, pair := range request.Auth {
tokens := strings.Split(pair, ":")
for _, basicAuthUser := range request.BasicAuth {
tokens := strings.Split(basicAuthUser, ":")
if len(tokens) == 2 {
out.Body.AuthUsers = append(out.Body.AuthUsers, &rest_model_zrok.AuthUser{Username: strings.TrimSpace(tokens[0]), Password: strings.TrimSpace(tokens[1])})
} else {
return nil, errors.Errorf("invalid username:password pair '%v'", pair)
return nil, errors.Errorf("invalid username:password '%v'", basicAuthUser)
}
}
}