mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
cleanups for OAuth in sdk.ShareRequest (#404)
This commit is contained in:
parent
957e50412e
commit
27fcf98fbd
@ -83,7 +83,7 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
|
|||||||
req := &sdk.ShareRequest{
|
req := &sdk.ShareRequest{
|
||||||
BackendMode: sdk.BackendMode(cmd.backendMode),
|
BackendMode: sdk.BackendMode(cmd.backendMode),
|
||||||
ShareMode: shareMode,
|
ShareMode: shareMode,
|
||||||
Auth: cmd.basicAuth,
|
BasicAuth: cmd.basicAuth,
|
||||||
Target: target,
|
Target: target,
|
||||||
}
|
}
|
||||||
if shareMode == sdk.PublicShareMode {
|
if shareMode == sdk.PublicShareMode {
|
||||||
|
@ -99,7 +99,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
req := &sdk.ShareRequest{
|
req := &sdk.ShareRequest{
|
||||||
BackendMode: sdk.BackendMode(cmd.backendMode),
|
BackendMode: sdk.BackendMode(cmd.backendMode),
|
||||||
ShareMode: sdk.PrivateShareMode,
|
ShareMode: sdk.PrivateShareMode,
|
||||||
Auth: cmd.basicAuth,
|
BasicAuth: cmd.basicAuth,
|
||||||
Target: target,
|
Target: target,
|
||||||
}
|
}
|
||||||
shr, err := sdk.CreateShare(root, req)
|
shr, err := sdk.CreateShare(root, req)
|
||||||
|
@ -105,10 +105,9 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
|||||||
BackendMode: sdk.BackendMode(cmd.backendMode),
|
BackendMode: sdk.BackendMode(cmd.backendMode),
|
||||||
ShareMode: sdk.PublicShareMode,
|
ShareMode: sdk.PublicShareMode,
|
||||||
Frontends: cmd.frontendSelection,
|
Frontends: cmd.frontendSelection,
|
||||||
Auth: cmd.basicAuth,
|
BasicAuth: cmd.basicAuth,
|
||||||
Target: target,
|
Target: target,
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd.oauthProvider != "" {
|
if cmd.oauthProvider != "" {
|
||||||
req.OauthProvider = cmd.oauthProvider
|
req.OauthProvider = cmd.oauthProvider
|
||||||
req.OauthEmailDomains = cmd.oauthEmailDomains
|
req.OauthEmailDomains = cmd.oauthEmailDomains
|
||||||
|
@ -22,9 +22,9 @@ const (
|
|||||||
type ShareRequest struct {
|
type ShareRequest struct {
|
||||||
BackendMode BackendMode
|
BackendMode BackendMode
|
||||||
ShareMode ShareMode
|
ShareMode ShareMode
|
||||||
Frontends []string
|
|
||||||
Auth []string
|
|
||||||
Target string
|
Target string
|
||||||
|
Frontends []string
|
||||||
|
BasicAuth []string
|
||||||
OauthProvider string
|
OauthProvider string
|
||||||
OauthEmailDomains []string
|
OauthEmailDomains []string
|
||||||
OauthAuthorizationCheckInterval time.Duration
|
OauthAuthorizationCheckInterval time.Duration
|
||||||
|
@ -26,14 +26,14 @@ func CreateShare(root env_core.Root, request *ShareRequest) (*Share, error) {
|
|||||||
return nil, errors.Errorf("unknown share mode '%v'", request.ShareMode)
|
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)
|
out.Body.AuthScheme = string(Basic)
|
||||||
for _, pair := range request.Auth {
|
for _, basicAuthUser := range request.BasicAuth {
|
||||||
tokens := strings.Split(pair, ":")
|
tokens := strings.Split(basicAuthUser, ":")
|
||||||
if len(tokens) == 2 {
|
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])})
|
out.Body.AuthUsers = append(out.Body.AuthUsers, &rest_model_zrok.AuthUser{Username: strings.TrimSpace(tokens[0]), Password: strings.TrimSpace(tokens[1])})
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.Errorf("invalid username:password pair '%v'", pair)
|
return nil, errors.Errorf("invalid username:password '%v'", basicAuthUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user