Add new argument to force a renewal of the token
This commit is contained in:
parent
0ba611b36b
commit
489e4335e1
2 changed files with 14 additions and 8 deletions
|
@ -41,7 +41,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetTokenURL -
|
// GetTokenURL -
|
||||||
func GetTokenURL() string {
|
func GetTokenURL(config *HTTPConfiguration) string {
|
||||||
|
googleOauthConfig.ClientID = config.ClientID
|
||||||
|
googleOauthConfig.ClientSecret = config.ClientSecret
|
||||||
|
|
||||||
url := googleOauthConfig.AuthCodeURL(oauthStateString, oauth2.AccessTypeOffline)
|
url := googleOauthConfig.AuthCodeURL(oauthStateString, oauth2.AccessTypeOffline)
|
||||||
|
|
||||||
// https://eveonline-third-party-documentation.readthedocs.io/en/latest/sso/authentication.html
|
// https://eveonline-third-party-documentation.readthedocs.io/en/latest/sso/authentication.html
|
||||||
|
|
17
main.go
17
main.go
|
@ -60,6 +60,7 @@ var (
|
||||||
cacheDBPath = flag.String("cache", "cache.ldb", "Path to the cache leveldb database.")
|
cacheDBPath = flag.String("cache", "cache.ldb", "Path to the cache leveldb database.")
|
||||||
insecureFlag = flag.Bool("insecure", false, "Do not check the HTTPS certificate")
|
insecureFlag = flag.Bool("insecure", false, "Do not check the HTTPS certificate")
|
||||||
logCalls = flag.Bool("httplog", false, "Log HTTP calls")
|
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()
|
var ctx = context.Background()
|
||||||
|
@ -95,8 +96,8 @@ func main() {
|
||||||
|
|
||||||
cToken := getDatabaseToken()
|
cToken := getDatabaseToken()
|
||||||
|
|
||||||
if cToken == nil {
|
if cToken == nil || *renewToken {
|
||||||
cToken = getNewAuthorizationToken()
|
cToken = getNewAuthorizationToken(httpConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpConfiguration.ConnectionToken = cToken
|
httpConfiguration.ConnectionToken = cToken
|
||||||
|
@ -106,7 +107,7 @@ func main() {
|
||||||
m, err := getCharacterInfo(client)
|
m, err := getCharacterInfo(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
cToken = getNewAuthorizationToken()
|
cToken = getNewAuthorizationToken(httpConfiguration)
|
||||||
httpConfiguration.ConnectionToken = cToken
|
httpConfiguration.ConnectionToken = cToken
|
||||||
|
|
||||||
client = InternalUtils.GetDefaultClient(cacheDB, httpConfiguration)
|
client = InternalUtils.GetDefaultClient(cacheDB, httpConfiguration)
|
||||||
|
@ -1000,9 +1001,10 @@ func getSchematicsInformation(swaggerclient *ESI.App, schematicID int32) (*Schem
|
||||||
return &schematicInfo, nil
|
return &schematicInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNewAuthorizationToken() *oauth2.Token {
|
func getNewAuthorizationToken(httpConfiguration *InternalUtils.HTTPConfiguration) *oauth2.Token {
|
||||||
http.HandleFunc("/", handleLogin)
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { handleLogin(w, r, httpConfiguration) })
|
||||||
http.HandleFunc("/callback", handleAuthenticationCallback)
|
http.HandleFunc("/callback", handleAuthenticationCallback)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
fmt.Println("No available token. Please visit http://localhost:3000 to renew.")
|
fmt.Println("No available token. Please visit http://localhost:3000 to renew.")
|
||||||
http.ListenAndServe(":3000", nil)
|
http.ListenAndServe(":3000", nil)
|
||||||
|
@ -1011,8 +1013,9 @@ func getNewAuthorizationToken() *oauth2.Token {
|
||||||
return <-messages
|
return <-messages
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLogin(w http.ResponseWriter, r *http.Request) {
|
func handleLogin(w http.ResponseWriter, r *http.Request, httpConfiguration *InternalUtils.HTTPConfiguration) {
|
||||||
url := InternalUtils.GetTokenURL()
|
url := InternalUtils.GetTokenURL(httpConfiguration)
|
||||||
|
log.Printf("URL will be %s\n", url)
|
||||||
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue