-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c39a1aa
commit f0abfa2
Showing
5 changed files
with
103 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package zsshlib | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"fmt" | ||
"github.com/openziti/edge-api/rest_model" | ||
"github.com/openziti/sdk-golang/ziti" | ||
"github.com/sirupsen/logrus" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Auth(flags *SshFlags) ziti.Context { | ||
oidcToken := "" | ||
var oidcErr error | ||
if flags.OIDC.Mode { | ||
oidcToken, oidcErr = OIDCFlow(context.Background(), flags) | ||
if oidcErr != nil { | ||
logrus.Fatalf("error performing OIDC flow: %v", oidcErr) | ||
} | ||
} | ||
|
||
conf := getConfig(flags.ZConfig) | ||
ctx, err := ziti.NewContext(conf) | ||
conf.Credentials.AddJWT(oidcToken) | ||
if err != nil { | ||
logrus.Fatalf("error creating ziti context: %v", err) | ||
} | ||
|
||
ctx.Events().AddMfaTotpCodeListener(func(c ziti.Context, detail *rest_model.AuthQueryDetail, response ziti.MfaCodeResponse) { | ||
reader := bufio.NewReader(os.Stdin) | ||
codeok := false | ||
for !codeok { | ||
fmt.Print("Enter MFA: ") | ||
code, _ := reader.ReadString('\n') | ||
code = strings.TrimSpace(code) | ||
fmt.Println("You entered:" + code + " - verifying") | ||
if err := response(code); err != nil { | ||
fmt.Println("error verifying MFA TOTP: ", err) | ||
} else { | ||
codeok = true | ||
} | ||
} | ||
}) | ||
|
||
if err = ctx.Authenticate(); err != nil { | ||
logrus.Errorf("error creating ziti context: %v", err) | ||
logrus.Fatalf("could not authenticate. verify your identity is correct and matches all necessary authentication conditions.") | ||
} | ||
|
||
return ctx | ||
} | ||
|
||
func ReadCode() string { | ||
code := "" | ||
reader := bufio.NewReader(os.Stdin) | ||
for code == "" { | ||
fmt.Print("Enter MFA: ") | ||
code, _ = reader.ReadString('\n') | ||
code = strings.TrimSpace(code) | ||
} | ||
return code | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters