Skip to content

Commit

Permalink
Added consts for hard coded values
Browse files Browse the repository at this point in the history
  • Loading branch information
tirthct committed Jan 16, 2024
1 parent b09f679 commit cafc95e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions authentication/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var (
authToken string
)

const (
RedirectURL = "http://127.0.0.1"
RedirectPort = "9998"
DefaultAuthURL = "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth"
CallbackHandler = "/oauth/callback"
)

func callbackHandler(w http.ResponseWriter, r *http.Request) {
queryParts, _ := url.ParseQuery(r.URL.RawQuery)

Expand All @@ -42,8 +49,8 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
}

func serve(wg *sync.WaitGroup) *http.Server {
server := &http.Server{Addr: ":9998"}
http.HandleFunc("/oauth/callback", callbackHandler)
server := &http.Server{Addr: fmt.Sprintf(":%s", RedirectPort)}
http.HandleFunc(CallbackHandler, callbackHandler)
go func() {
defer wg.Done() // let main know we are done cleaning up

Expand Down Expand Up @@ -73,10 +80,10 @@ func VerifyLogin(clientID string) (string, error) {
ClientSecret: "",
Scopes: []string{"openid"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth",
TokenURL: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token",
AuthURL: DefaultAuthURL,
TokenURL: DefaultTokenURL,
},
RedirectURL: "http://127.0.0.1:9998/oauth/callback",
RedirectURL: fmt.Sprintf("%s:%s%s", RedirectURL, RedirectPort, CallbackHandler),
}
verifier = oauth2.GenerateVerifier()

Expand Down

0 comments on commit cafc95e

Please sign in to comment.