|
1 | 1 | package cloud |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "encoding/json" |
5 | 6 | "fmt" |
6 | 7 | "io/ioutil" |
@@ -28,7 +29,7 @@ func CheckAuth(provider *Provider) (string, *api.Cluster, *api.AuthInfo, error) |
28 | 29 | // GetClusterConfig retrieves the cluster and authconfig from the devspace cloud |
29 | 30 | func GetClusterConfig(provider *Provider) (string, *api.Cluster, *api.AuthInfo, error) { |
30 | 31 | client := &http.Client{} |
31 | | - req, err := http.NewRequest("GET", provider.GetConfig, nil) |
| 32 | + req, err := http.NewRequest("GET", provider.Host+GetClusterConfigEndpoint, nil) |
32 | 33 | if err != nil { |
33 | 34 | return "", nil, nil, err |
34 | 35 | } |
@@ -81,17 +82,18 @@ func GetClusterConfig(provider *Provider) (string, *api.Cluster, *api.AuthInfo, |
81 | 82 |
|
82 | 83 | // Login logs the user into the devspace cloud |
83 | 84 | func Login(provider *Provider) (string, *api.Cluster, *api.AuthInfo, error) { |
| 85 | + ctx := context.Background() |
84 | 86 | tokenChannel := make(chan string) |
85 | 87 |
|
86 | | - log.StartWait("Logging into cloud " + provider.Login + " ...") |
87 | | - server := startServer(tokenChannel) |
| 88 | + log.StartWait("Logging into cloud " + provider.Host + LoginEndpoint + " ...") |
| 89 | + server := startServer(provider.Host+LoginSuccessEndpoint, tokenChannel) |
88 | 90 |
|
89 | | - open.Start(provider.Login) |
| 91 | + open.Start(provider.Host + LoginEndpoint) |
90 | 92 |
|
91 | 93 | token := <-tokenChannel |
92 | 94 | close(tokenChannel) |
93 | 95 |
|
94 | | - err := server.Shutdown(nil) |
| 96 | + err := server.Shutdown(ctx) |
95 | 97 | if err != nil { |
96 | 98 | return "", nil, nil, err |
97 | 99 | } |
@@ -185,19 +187,19 @@ func UpdateKubeConfig(contextName string, cluster *api.Cluster, authInfo *api.Au |
185 | 187 | return kubeconfig.WriteKubeConfig(config, clientcmd.RecommendedHomeFile) |
186 | 188 | } |
187 | 189 |
|
188 | | -func startServer(tokenChannel chan string) *http.Server { |
| 190 | +func startServer(redirectURI string, tokenChannel chan string) *http.Server { |
189 | 191 | srv := &http.Server{Addr: ":25853"} |
190 | 192 |
|
191 | 193 | http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) { |
192 | | - fmt.Fprintf(w, "<script type=\"text/javascript\">window.close();</script>") |
193 | | - |
194 | 194 | keys, ok := r.URL.Query()["token"] |
195 | 195 | if !ok || len(keys[0]) < 1 { |
196 | 196 | log.Fatal("Bad request") |
197 | 197 | } |
198 | 198 |
|
199 | 199 | log.StopWait() |
200 | 200 | tokenChannel <- keys[0] |
| 201 | + |
| 202 | + http.Redirect(w, r, redirectURI, http.StatusSeeOther) |
201 | 203 | }) |
202 | 204 |
|
203 | 205 | go func() { |
|
0 commit comments