diff --git a/resources/wasm/oauth/main.go b/resources/wasm/oauth/main.go index cb6f63d..358fd42 100644 --- a/resources/wasm/oauth/main.go +++ b/resources/wasm/oauth/main.go @@ -72,7 +72,7 @@ func main() { formData.Set("code_verifier", localStorage.Call("getItem", "OAUTH-verifier").String()) // Create the request - requestUri, err := url.JoinPath(js.Global().Get("window").Get("location").Get("origin").String(), js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String()+"/token") + requestUri, err := url.JoinPath(js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String(), "/oauth/token") if err != nil { statusBox.Set("innerText", "Error joining URL: "+err.Error()) tryAgain.Set("style", "") @@ -104,7 +104,7 @@ func main() { if response.StatusCode == 200 { // Fetch userinfo - requestUri, err := url.JoinPath(js.Global().Get("window").Get("location").Get("origin").String(), js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String()+"/userinfo") + requestUri, err := url.JoinPath(js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String(), "/oauth/userinfo") if err != nil { statusBox.Set("innerText", "Error joining URL: "+err.Error()) tryAgain.Set("style", "") @@ -192,7 +192,14 @@ func main() { localStorage.Call("setItem", "OAUTH-verifier", verifier) // Redirect to the authorization page - js.Global().Get("window").Get("location").Call("replace", js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String()+"/authorize?response_type=code&client_id="+js.Global().Get("document").Call("getElementById", "clientId").Get("innerText").String()+"&redirect_uri="+url.QueryEscape(js.Global().Get("window").Get("location").Get("origin").String()+"/oauth")+"&code_challenge="+verifierChallenge+"&code_challenge_method=S256") + authorizeUri, err := url.JoinPath(js.Global().Get("document").Call("getElementById", "authorizationUri").Get("innerText").String(), "/authorize?response_type=code&client_id="+js.Global().Get("document").Call("getElementById", "clientId").Get("innerText").String()+"&redirect_uri="+url.QueryEscape(js.Global().Get("window").Get("location").Get("origin").String()+"/oauth")+"&code_challenge="+verifierChallenge+"&code_challenge_method=S256") + if err != nil { + statusBox.Set("innerText", "Error joining URL: "+err.Error()) + tryAgain.Set("style", "") + return + } + + js.Global().Get("window").Get("location").Call("replace", authorizeUri) } }()