Skip to content

Commit

Permalink
MFA flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Apr 9, 2020
1 parent ddba921 commit 4a157e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cmd/openvpn-onelogin-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ func readConfig() onelogin.Config {
return config
}

func getPasswordAndToken() (string, string, error) {
func getPasswordAndToken(isMFAEnabled bool) (string, string, error) {
password := os.Getenv("password")
if len(password) < 7 {
return "", "", fmt.Errorf("No OTP Supplied")
if isMFAEnabled {
if len(password) < 7 {
return "", "", fmt.Errorf("No OTP Supplied")
}
return password[0 : len(password)-6], password[len(password)-6:], nil
}
return password[0 : len(password)-6], password[len(password)-6:], nil
return password, "", nil
}

func main() {
Expand All @@ -47,7 +50,7 @@ func main() {

o := onelogin.New(readConfig())

password, passwordToken, err := getPasswordAndToken()
password, passwordToken, err := getPasswordAndToken(o.IsMFAEnabled())
if err != nil {
logger.Infof("Authentication failed: no password/otp supplied")
os.Exit(1)
Expand Down
7 changes: 7 additions & 0 deletions pkg/onelogin/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,10 @@ func (o *onelogin) VerifyFactor(token string, params VerifyFactorParams) (Sessio

return sessionResponse, nil
}

func (o *onelogin) IsMFAEnabled() bool {
if o.config.MFA == true {
return true
}
return false
}
1 change: 1 addition & 0 deletions pkg/onelogin/onelogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type Config struct {
URL string `toml:"ONELOGIN_URL"`
ClientID string `toml:"ONELOGIN_CLIENT_ID"`
ClientSecret string `toml:"ONELOGIN_CLIENT_SECRET"`
MFA bool `toml:"ONELOGIN_MFA"`
}
type onelogin struct {
config Config
Expand Down

0 comments on commit 4a157e4

Please sign in to comment.