Added redirectURL argument for oauth2 callback
This commit is contained in:
@@ -731,6 +731,7 @@ func main() {
|
|||||||
ShardCount = flag.String("c", "", "Number of shards")
|
ShardCount = flag.String("c", "", "Number of shards")
|
||||||
Owner = flag.String("o", "", "Owner ID")
|
Owner = flag.String("o", "", "Owner ID")
|
||||||
Port = flag.Int("p", 0, "Web server port")
|
Port = flag.Int("p", 0, "Web server port")
|
||||||
|
RedirectURL = flag.String("r", "", "Address where the web server will be available without slash at the end. For example: \"http://bot.example.org:12345\"")
|
||||||
Ci = flag.Int("ci", 0, "ClientID")
|
Ci = flag.Int("ci", 0, "ClientID")
|
||||||
Cs = flag.String("cs", "", "ClientSecret")
|
Cs = flag.String("cs", "", "ClientSecret")
|
||||||
err error
|
err error
|
||||||
@@ -738,9 +739,9 @@ func main() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Start Webserver if a valid port is provided and if ClientID and ClientSecret are set
|
// Start Webserver if a valid port is provided and if ClientID and ClientSecret are set
|
||||||
if *Port != 0 && *Port >= 1 && *Ci != 0 && *Cs != "" {
|
if *Port != 0 && *Port >= 1 && *Ci != 0 && *Cs != "" && *RedirectURL != "" {
|
||||||
log.Infoln("Starting web server on port " + strconv.Itoa(*Port))
|
log.Infoln("Starting web server on port " + strconv.Itoa(*Port))
|
||||||
go startWebServer(strconv.Itoa(*Port), strconv.Itoa(*Ci), *Cs)
|
go startWebServer(strconv.Itoa(*Port), strconv.Itoa(*Ci), *Cs, *RedirectURL)
|
||||||
} else {
|
} else {
|
||||||
log.Infoln("Required web server arguments missing or invalid. Skipping web server start.")
|
log.Infoln("Required web server arguments missing or invalid. Skipping web server start.")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -33,9 +33,10 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// startWebServer with the port provided
|
// startWebServer with the port provided
|
||||||
func startWebServer(port string, ci string, cs string) {
|
func startWebServer(port string, ci string, cs string, redirectURL string) {
|
||||||
discordOauthConfig.ClientID = ci
|
discordOauthConfig.ClientID = ci
|
||||||
discordOauthConfig.ClientSecret = cs
|
discordOauthConfig.ClientSecret = cs
|
||||||
|
discordOauthConfig.RedirectURL = redirectURL + "/discordCallback"
|
||||||
http.HandleFunc("/", handleMain)
|
http.HandleFunc("/", handleMain)
|
||||||
http.HandleFunc("/discordLogin", handlediscordLogin)
|
http.HandleFunc("/discordLogin", handlediscordLogin)
|
||||||
http.HandleFunc("/discordCallback", handlediscordCallback)
|
http.HandleFunc("/discordCallback", handlediscordCallback)
|
||||||
@@ -43,7 +44,6 @@ func startWebServer(port string, ci string, cs string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMain(w http.ResponseWriter, r *http.Request) {
|
func handleMain(w http.ResponseWriter, r *http.Request) {
|
||||||
discordOauthConfig.RedirectURL = "http://" + r.Host + "/discordCallback"
|
|
||||||
fmt.Fprintf(w, htmlIndex)
|
fmt.Fprintf(w, htmlIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user