Skip to content

Instantly share code, notes, and snippets.

@Apurer
Created March 13, 2024 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Apurer/2d8459711f8fb7e9dde20f3187c327b5 to your computer and use it in GitHub Desktop.
Save Apurer/2d8459711f8fb7e9dde20f3187c327b5 to your computer and use it in GitHub Desktop.
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