diff --git a/internals/httpclient.go b/internals/httpclient.go index aa56896..cc4f761 100644 --- a/internals/httpclient.go +++ b/internals/httpclient.go @@ -41,7 +41,10 @@ var ( ) // GetTokenURL - -func GetTokenURL() string { +func GetTokenURL(config *HTTPConfiguration) string { + googleOauthConfig.ClientID = config.ClientID + googleOauthConfig.ClientSecret = config.ClientSecret + url := googleOauthConfig.AuthCodeURL(oauthStateString, oauth2.AccessTypeOffline) // https://eveonline-third-party-documentation.readthedocs.io/en/latest/sso/authentication.html diff --git a/main.go b/main.go index 63f9ebe..956a688 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,7 @@ var ( cacheDBPath = flag.String("cache", "cache.ldb", "Path to the cache leveldb database.") insecureFlag = flag.Bool("insecure", false, "Do not check the HTTPS certificate") logCalls = flag.Bool("httplog", false, "Log HTTP calls") + renewToken = flag.Bool("renewToken", false, "Renew the token even if it is still valid") ) var ctx = context.Background() @@ -95,8 +96,8 @@ func main() { cToken := getDatabaseToken() - if cToken == nil { - cToken = getNewAuthorizationToken() + if cToken == nil || *renewToken { + cToken = getNewAuthorizationToken(httpConfiguration) } httpConfiguration.ConnectionToken = cToken @@ -106,7 +107,7 @@ func main() { m, err := getCharacterInfo(client) if err != nil { log.Println(err) - cToken = getNewAuthorizationToken() + cToken = getNewAuthorizationToken(httpConfiguration) httpConfiguration.ConnectionToken = cToken client = InternalUtils.GetDefaultClient(cacheDB, httpConfiguration) @@ -1000,9 +1001,10 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*Schem return &schematicInfo, nil } -func getNewAuthorizationToken() *oauth2.Token { - http.HandleFunc("/", handleLogin) +func getNewAuthorizationToken(httpConfiguration *InternalUtils.HTTPConfiguration) *oauth2.Token { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { handleLogin(w, r, httpConfiguration) }) http.HandleFunc("/callback", handleAuthenticationCallback) + go func() { fmt.Println("No available token. Please visit http://localhost:3000 to renew.") http.ListenAndServe(":3000", nil) @@ -1011,8 +1013,9 @@ func getNewAuthorizationToken() *oauth2.Token { return <-messages } -func handleLogin(w http.ResponseWriter, r *http.Request) { - url := InternalUtils.GetTokenURL() +func handleLogin(w http.ResponseWriter, r *http.Request, httpConfiguration *InternalUtils.HTTPConfiguration) { + url := InternalUtils.GetTokenURL(httpConfiguration) + log.Printf("URL will be %s\n", url) http.Redirect(w, r, url, http.StatusTemporaryRedirect) }