Created
March 13, 2024 13:09
-
-
Save Apurer/2d8459711f8fb7e9dde20f3187c327b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"github.com/skratchdot/open-golang/open" | |
) | |
var bearerToken string | |
func main() { | |
samlLoginURL := "https://your-idp.com/start-saml-login" | |
redirectURI := "http://localhost:8080/saml/callback" | |
err := open.Run(samlLoginURL) | |
if err != nil { | |
log.Fatalf("Failed to open web browser: %v", err) | |
} | |
http.HandleFunc("/saml/callback", func(w http.ResponseWriter, r *http.Request) { | |
bearerToken = "simulated_bearer_token_from_saml_response" | |
fmt.Fprintf(w, "Authentication successful. You can close this window.") | |
callConfluenceAPI() | |
}) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func callConfluenceAPI() { | |
url := "https://your-confluence-site.atlassian.net/wiki/rest/api/content" | |
req, err := http.NewRequest("GET", url, nil) | |
if err != nil { | |
fmt.Println("Error creating request:", err) | |
return | |
} | |
req.Header.Add("Authorization", "Bearer "+bearerToken) | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
fmt.Println("Error sending request:", err) | |
return | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println("Error reading response body:", err) | |
return | |
} | |
fmt.Println(string(body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment