Skip to content

Commit

Permalink
Add non-obvious callback address for hoop client (#51)
Browse files Browse the repository at this point in the history
* Add non-obvious callback address for hoop client
  • Loading branch information
sandromello authored Nov 7, 2022
1 parent c8331f9 commit 45b34d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions client/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"runtime"
"strings"

pb "github.com/runopsio/hoop/common/proto"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -104,8 +105,7 @@ func doLogin(args []string) error {
}

http.HandleFunc("/callback", loginCallback)
go http.ListenAndServe(":3333", nil)

go http.ListenAndServe(pb.ClientLoginCallbackAddress, nil)
if err := openBrowser(loginUrl); err != nil {
fmt.Printf("Browser failed to open. \nPlease click on the link below:\n\n%s\n\n", loginUrl)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func requestForUrl(email, apiUrl string) (string, error) {

var l login
if err := json.Unmarshal(b, &l); err != nil {
return "", nil
return "", err
}

return l.Url, nil
Expand Down
2 changes: 2 additions & 0 deletions common/proto/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ const (

ConnectionOriginAgent = "agent"
ConnectionOriginClient = "client"

ClientLoginCallbackAddress string = "127.0.0.1:3587"
)
8 changes: 5 additions & 3 deletions gateway/security/api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package security

import (
"github.com/gin-gonic/gin"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
pb "github.com/runopsio/hoop/common/proto"
)

type (
Expand Down Expand Up @@ -46,8 +49,7 @@ func (h *Handler) Callback(c *gin.Context) {
}

func defaultRedirect(c *gin.Context) string {
defaultUrl := "http://localhost:3333/callback"

defaultUrl := fmt.Sprintf("http://%s/callback", pb.ClientLoginCallbackAddress)
redirect := c.Query("redirect")
if redirect == "" {
redirect = defaultUrl
Expand Down

0 comments on commit 45b34d5

Please sign in to comment.